﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.Collections;
using System.Data.OleDb;


namespace LCWMS
{
    public partial class w_itf002 : DockContent
    {

        //返回的商品信息 格式sku
        public static string str_skucode;
        private string str_updatesql;
        private DataSet ds_update;
        private DataSet dscustomer;
        string str_time = "";
        decimal d_sum = 0;
        decimal d_count = 0;
        private ExcelBase excel;
        private ExcelBE be;
        public w_itf002()
        {
            InitializeComponent();
            dgv_asn.AutoGenerateColumns = false;

        }
        private void w_itf002_Load(object sender, EventArgs e)
        {
            //获取按钮权限
            string str_right;
            str_right = main.g_class.comm_getright("w_itf002", main.g_right_dataset);

            //导入
            if (str_right.Substring(0, 1) == "0")
            {
                btn_inexcel.Visible = false;
            }
            else
            {
                btn_inexcel.Visible = true;
            }
            main.g_class.comm_changeControl(this, main.g_win_dataset);
            //导出
            if (str_right.Substring(0, 2) == "0")
            {
                btn_outexcel.Visible = false;
            }
            else
            {
                btn_outexcel.Visible = true;
            }

            main.g_class.comm_changeControl(this, main.g_win_dataset);
            //表头
            DataTable add_header = new DataTable();
            add_header.Columns.Add("consignor");
            add_header.Columns.Add("asn_no");
            add_header.Columns.Add("customer_order_no");
            add_header.Columns.Add("order_day");
            add_header.Columns.Add("asn_type");
            add_header.Columns.Add("supply");
            add_header.Columns.Add("in_tax");
            add_header.Columns.Add("out_tax");
            add_header.Columns.Add("arrive_plan_day");
            add_header.Columns.Add("arrive_deadline");
            add_header.Columns.Add("asn_status");
            add_header.Columns.Add("arrive_status");
            add_header.Columns.Add("buyer");
            add_header.Columns.Add("main_dist");
            add_header.Columns.Add("made_time");
            add_header.Columns.Add("maker");
            add_header.Columns.Add("ext_dist");
            //明细
            DataTable add_detail = new DataTable();
            add_detail.Columns.Add("consignor");
            add_detail.Columns.Add("asn_no");
            add_detail.Columns.Add("asn_line_no");
            add_detail.Columns.Add("sku");
            add_detail.Columns.Add("pack_code");
            add_detail.Columns.Add("order_qty_m");
            add_detail.Columns.Add("present_qty_m");
            add_detail.Columns.Add("order_price");
            add_detail.Columns.Add("order_unit");
            add_detail.Columns.Add("main_dist");
            add_detail.Columns.Add("made_time");
            add_detail.Columns.Add("maker");

            DataTable dt_execl = new DataTable();
            dt_execl.Columns.Add("customer_order_no");
            dt_execl.Columns.Add("sku");
            dgv_execl.DataSource = dt_execl;


            //初始化货主编码 
            try
            {
                dscustomer = main.g_class.comm_get_consignor();
                cb_consignor.ValueMember = "consignor";
                cb_consignor.DisplayMember = "consignor";
                DataRow drnew;
                drnew = dscustomer.Tables[0].NewRow();
                drnew["consignor"] = "";
                drnew["consignor_name"] = "";
                dscustomer.Tables[0].Rows.Add(drnew);
                cb_consignor.DataSource = dscustomer.Tables[0];
                if (dscustomer.Tables[0].Rows.Count > 0) tb_cusname.Text = dscustomer.Tables[0].Rows[0][1].ToString().Trim();

                dtp_made_time.CustomFormat = "yyyy.MM.dd";
                dtp_made_time.Format = DateTimePickerFormat.Custom;
                dtp_made_time_end.CustomFormat = "yyyy.MM.dd";
                dtp_made_time_end.Format = DateTimePickerFormat.Custom;
                //dtp_made_time.Value = System.Convert.ToDateTime(DateTime.Now.ToString("yyyy.MM.dd").Trim());
                //dtp_end.Value = System.Convert.ToDateTime(DateTime.Now.AddDays(7).ToString("yyyy.MM.dd").Trim());

            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Consignor's Information", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
            try
            {
                string str_time_sql = "";
                if (main.dbtype == "SQL")
                {
                    str_time_sql = "SELECT CONVERT(char(11),getdate(),102)";
                    str_time = main.dbservice.Sql_exec_selectstring(str_time_sql);
                }
                else
                {
                    str_time_sql = "select to_char(sysdate,'yyyy.MM.dd') from dual";
                    str_time = main.dbservice.oracle_exec_selectstring(str_time_sql);
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(ee.Message);
                str_time = DateTime.Now.ToString("yyyy.MM.dd");
            }
        }
        //创建SQL与数据集
        private void f_getsql(string stemp1, string stemp2)
        {
            str_updatesql = "select inv_org,consignor,so_no,so_line_no,sku,pack_code,plan_so_qty_m,order_price,lot_attribute1,lot_attribute2,lot_attribute3,lot_attribute4," +
                           " lot_attribute5,lot_attribute6,lot_attribute7,lot_attribute8,lot_attribute9,lot_attribute10,lot_attribute11,lot_attribute12,lot_attribute13," +
                           " lot_attribute14,lot_attribute15,main_dist,made_time,maker " +
                           " from " + main.g_space + ".so_ship_detail where inv_org = '" + main.g_org + "' and consignor ='" + stemp1 + "' and so_no ='" + stemp2 + "' ";
            if (main.dbtype == "SQL")
            {
                ds_update = main.dbservice.Sql_exec_selectsql(str_updatesql);
            }
            else
            {
                ds_update = main.dbservice.oracle_exec_selectsql(str_updatesql);
            }
        }
        //创建SQL与数据集
        private void f_getsql_JS(string stemp1, string stemp2)
        {
            str_updatesql = "select inv_org,consignor,so_no,so_line_no,sku,pack_code,plan_so_qty_m,order_price,lot_attribute1,lot_attribute2,lot_attribute3,lot_attribute4," +
                           " lot_attribute5,lot_attribute6,lot_attribute7,lot_attribute8,lot_attribute9,lot_attribute10,lot_attribute11,lot_attribute12,lot_attribute13," +
                           " lot_attribute14,lot_attribute15,main_dist,made_time,maker,plan_so_qty_s,order_unit,convert_modulus,main_sub_flag,plan_gross_weight,plan_net_weight,plan_cubage,standby_6,standby_7,so_status,standby_2 " +
                           ",ship_qty_m,ship_qty_s,standby_3 from " + main.g_space + ".so_ship_detail where inv_org = '" + main.g_org + "' and consignor ='" + stemp1 + "' and so_no ='" + stemp2 + "' ";
            if (main.dbtype == "SQL")
            {
                ds_update = main.dbservice.Sql_exec_selectsql(str_updatesql);
            }
            else
            {
                ds_update = main.dbservice.oracle_exec_selectsql(str_updatesql);
            }
        }
        //创建SQL与数据集
        private void f_getsql_WXJS(string stemp1, string stemp2)
        {
            str_updatesql = "select inv_org,consignor,so_no,so_line_no,sku,pack_code,plan_so_qty_m,order_price,lot_attribute1,lot_attribute2,lot_attribute3,lot_attribute4," +
                           " lot_attribute5,lot_attribute6,lot_attribute7,lot_attribute8,lot_attribute9,lot_attribute10,lot_attribute11,lot_attribute12,lot_attribute13," +
                           " lot_attribute14,lot_attribute15,main_dist,made_time,maker,plan_so_qty_s,order_unit,convert_modulus,main_sub_flag,plan_gross_weight,plan_net_weight,plan_cubage,standby_6,standby_7,so_status " +
                           " from " + main.g_space + ".so_ship_detail where inv_org = '" + main.g_org + "' and consignor ='" + stemp1 + "' and so_no ='" + stemp2 + "' ";
            if (main.dbtype == "SQL")
            {
                ds_update = main.dbservice.Sql_exec_selectsql(str_updatesql);
            }
            else
            {
                ds_update = main.dbservice.oracle_exec_selectsql(str_updatesql);
            }
        }
        private void f_getsql_WXJS_CP(string stemp1, string stemp2)
        {
            str_updatesql = "select inv_org,consignor,so_no,so_line_no,sku,pack_code,plan_so_qty_m,plan_so_qty_s,ship_qty_m,ship_qty_s,order_price,lot_attribute1,lot_attribute2,lot_attribute3,lot_attribute4," +
                           " lot_attribute5,lot_attribute6,lot_attribute7,lot_attribute8,lot_attribute9,lot_attribute10,lot_attribute11,lot_attribute12,lot_attribute13," +
                           " lot_attribute14,lot_attribute15,main_dist,made_time,maker,order_unit,convert_modulus,main_sub_flag,plan_gross_weight,plan_net_weight,plan_cubage,standby_6,standby_7,so_status,standby_2,standby_3 " +
                           " from " + main.g_space + ".so_ship_detail where inv_org = '" + main.g_org + "' and consignor ='" + stemp1 + "' and so_no ='" + stemp2 + "' ";
            if (main.dbtype == "SQL")
            {
                ds_update = main.dbservice.Sql_exec_selectsql(str_updatesql);
            }
            else
            {
                ds_update = main.dbservice.oracle_exec_selectsql(str_updatesql);
            }
        }
        //导入excel
        private void btn_inexcel_Click(object sender, EventArgs e)
        {
            string str_path;
            str_path = tb_file.Text.Trim();
            if (str_path.Trim() == "") return;

            if (dgv_execl.Rows.Count > 0)
            {
                ((DataTable)dgv_execl.DataSource).Rows.Clear();
            }
            //调用导入数据方法 
            if (comboBox1.Text.Trim() == "标准模板")
            {
                EcxelToDataGridView(str_path, this.dgv_asn);
                f_getsql("", "");
            }
            else if (main.g_class.comm_getconversestring(comboBox1.Text.Trim(), main.g_info_dataset).ToLower() == "control products")
            {
                EcxelToDataGridView_JS(str_path, this.dgv_asn);
                f_getsql_JS("", "");
            }
            else if (main.g_class.comm_getconversestring(comboBox1.Text.Trim(), main.g_info_dataset).ToLower() == "service parts")
            {
                EcxelToDataGridView_JS2(str_path, this.dgv_asn);
                f_getsql_JS("", "");
            }
            else if (main.g_class.comm_getconversestring(comboBox1.Text.Trim(), main.g_info_dataset).ToLower() == "供应商退货")
            {
                EcxelToDataGridView_JS_openpo(str_path, this.dgv_asn);
                f_getsql_JS("", "");
            }
            else if (comboBox1.Text.Trim() == "出口出货单")
            {
                EcxelToDataGridView_JS3(str_path, this.dgv_asn);
                f_getsql_JS("", "");
            }
            else if (comboBox1.Text.Trim() == "sh office")
            {
                EcxelToDataGridView_JS4(str_path, this.dgv_asn);
                f_getsql_JS("", "");
            }
            else if (comboBox1.Text.Trim() == "无锡江森原料库模板")
            {
                EcxelToDataGridView_WXJS(str_path, this.dgv_asn);
                f_getsql_WXJS_CP("", "");
            }
            else if (comboBox1.Text.Trim() == "无锡江森成品库模板")
            {
                EcxelToDataGridView_WXJS_CP(str_path, this.dgv_asn);
                f_getsql_WXJS_CP("", "");
            }
           
            else
            {

                MessageBox.Show("请选择模板类型!");
                comboBox1.Focus();
                return;
            }
            if (dgv_asn.Rows.Count == 0) return;
            btn_save.Enabled = true;
            btn_cancel.Enabled = true;
            btn_query.Enabled = false;
            btn_outexcel.Enabled = false;
            btn_inexcel.Enabled = false;
            //MessageBox.Show(main.g_class.comm_getchangestring("Success to Excel ", main.g_info_dataset) + "!");
        }

        //选取文件
        private void btn_file_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text.Trim() == "")
            {
                MessageBox.Show("请选择模板类型!");
                comboBox1.Focus();
                return;
            }
            dgv_asn.DataSource = null;
            dgv_export.DataSource = null;
            //打开一个文件选择框
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "Excel文件";
            ofd.FileName = "";
            //ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);//为了获取特定的系统文件夹，可以使用System.Environment类的静态方法GetFolderPath()。该方法接受一个Environment.SpecialFolder枚举，其中可以定义要返回路径的哪个系统目录
            ofd.Filter = "Excel文件(*.xls)|*.xls";
            ofd.ValidateNames = true;     //文件有效性验证ValidateNames，验证用户输入是否是一个有效的Windows文件名
            ofd.CheckFileExists = true;  //验证路径有效性
            ofd.CheckPathExists = true; //验证文件有效性
            dgv_export.Visible = false;
            dgv_asn.Visible = true;
            string strName = string.Empty;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                strName = ofd.FileName;
            }

            if (strName == "")
            {
                MessageBox.Show("没有选择Excel文件！无法进行数据导入");
                return;
            }

            tb_file.Text = strName;
            //取文件名
            GetDataFromExcelWithAppointSheetName(strName);
        }
        public void EcxelToDataGridView(string filePath, DataGridView dgv)
        {
            //根据路径打开一个Excel文件并将数据填充到DataSet中
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            string str_file;
            str_file = cbx_file.Text.Trim() + "$";
            OleDbDataAdapter myCommand = null;
            DataSet ds = null;
            strExcel = "select  * from  [" + str_file + "]";
            myCommand = new OleDbDataAdapter(strExcel, strConn);
            ds = new DataSet();
            myCommand.Fill(ds, "table1");

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (ds.Tables[0].Rows[i][0].ToString().Trim() == "货主编码" || ds.Tables[0].Rows[i][0].ToString().Trim() == "")
                {
                    ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                    i = i - 1;
                }

            }
            //根据DataGridView的列构造一个新的DataTable
            DataTable tb = new DataTable();
            foreach (DataGridViewColumn dgvc in dgv.Columns)
            {

                if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                {
                    DataColumn dc = new DataColumn();
                    dc.ColumnName = dgvc.DataPropertyName;
                    //dc.DataType = dgvc.ValueType;//若需要限制导入时的数据类型则取消注释，前提是DataGridView必须先绑定一个数据源那怕是空的DataTable
                    tb.Columns.Add(dc);
                }
            }

            //根据Excel的行逐一对上面构造的DataTable的列进行赋值
            foreach (DataRow excelRow in ds.Tables[0].Rows)
            {
                int i = 0;
                DataRow dr = tb.NewRow();
                foreach (DataColumn dc in tb.Columns)
                {

                    dr[dc] = excelRow[i];
                    i++;
                }
                tb.Rows.Add(dr);
            }
            //在DataGridView中显示导入的数据
            dgv.DataSource = tb;
        }

        public void EcxelToDataGridView_JS_openpo(string filePath, DataGridView dgv)
        {
            //根据路径打开一个Excel文件并将数据填充到DataSet中
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            string str_file;
            //string str_sql = "";
            //DataSet ds_temp;
            str_file = cbx_file.Text.Trim();
            if (str_file.Substring(str_file.Length - 1) == "'")
            {
                str_file = str_file.Substring(0, str_file.Length - 1);
            }
            if (str_file.Substring(str_file.Length - 1) != "$")
            {
                str_file = str_file + "$";
            }
            if (str_file.Substring(0, 1) == "'")
            {
                str_file = str_file.Substring(1);
            }
            DataTable dt_execl = new DataTable();
            dt_execl.Columns.Add("status");
            dt_execl.Columns.Add("Purch.Doc.");
            dt_execl.Columns.Add("Doc. Date");
            dt_execl.Columns.Add("Item");
            dt_execl.Columns.Add("A");
            dt_execl.Columns.Add("Material");
            dt_execl.Columns.Add("Short Text.Doc.");
            dt_execl.Columns.Add("Quantity");
            dt_execl.Columns.Add("To be del.");
            dt_execl.Columns.Add("OUn");
            dt_execl.Columns.Add("Plnt");
            dt_execl.Columns.Add("SLoc");
            dt_execl.Columns.Add("Vendor/supplying plant");
            OleDbDataAdapter myCommand = null;
            DataSet ds = null;
            dgv_execl.DataSource = dt_execl;
            strExcel = "select  * from  [" + str_file + "]";
            try
            {
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");


                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i][0].ToString().Trim() == "货主编码" || ds.Tables[0].Rows[i][0].ToString().Trim() == "" || ds.Tables[0].Rows[i][0].ToString().Trim() == "Purch.Doc.")
                    {
                        ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                        i = i - 1;
                    }
                }
                d_sum = ds.Tables[0].Rows.Count;
                DataSet ds_temp2;
                string str_sql2 = "";
                ds.Tables[0].Columns.Add("sku");
                ds.Tables[0].Columns.Add("pack_code");
                progressBar1.Maximum = ds.Tables[0].Rows.Count;
                progressBar1.Value = 0;
                progressBar1.Visible = true;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    progressBar1.Value = i;
                    #region SKU

                    str_sql2 = "  SELECT *from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='" + ds.Tables[0].Rows[i]["F10"].ToString().Trim() + "' and sku='" + ds.Tables[0].Rows[i]["F5"].ToString().Trim() + "' and main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        if (ds_temp2.Tables[0].Rows.Count <= 0) //说明没有记录  
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();

                            dr["Purch.Doc."] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["Doc. Date"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Item"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["A"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Short Text.Doc."] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["Quantity"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["To be del."] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["OUn"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["SLoc"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["Vendor/supplying plant"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                        else
                        {
                            ds.Tables[0].Rows[i]["sku"] = ds_temp2.Tables[0].Rows[0]["sku"].ToString().Trim();
                            ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show("查找商品档案失败!" + ee.ToString());
                        return;
                    }

                    #endregion

                    # region 包装编码
                    //根据SKU找出包装

                    str_sql2 = "select * from " + main.g_space + ".mst_pack where inv_org = '" + main.g_org + "' and consignor = '" + ds.Tables[0].Rows[i]["F10"].ToString().Trim() + "' and sku ='" + ds.Tables[0].Rows[i]["sku"].ToString() + "'   and  main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        //显示详细的信息
                        if (ds_temp2.Tables[0].Rows.Count > 0)
                        {
                            //ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                        }
                        else
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();

                            dr["Purch.Doc."] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["Doc. Date"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Item"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["A"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Short Text.Doc."] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["Quantity"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["To be del."] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["OUn"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["SLoc"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["Vendor/supplying plant"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get pack's Information", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                    #endregion

                    #region 供应商

                    try
                    {
                        DataSet ds_supply;
                        string str_supply = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                        string[] aa = str_supply.Split(' ');
                        if (aa.Length > 0)
                        {
                            str_supply = aa[0].Trim();

                            if (main.dbtype == "SQL")
                            {
                                str_sql2 = "select ltrim(rtrim(consignor)) consignor,ltrim(rtrim(consignor_name)) consignor_name from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and supply_flag = '1' and consignor = '" + str_supply + "' order by consignor";
                                ds_supply = main.dbservice.Sql_exec_selectsql(str_sql2);
                            }
                            else
                            {
                                str_sql2 = "select trim(consignor) consignor,trim(consignor_name) consignor_name from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and supply_flag = '1'  and consignor = '" + str_supply + "'  order by consignor";
                                ds_supply = main.dbservice.oracle_exec_selectsql(str_sql2);
                            }
                            if (ds_supply.Tables[0].Rows.Count <= 0)
                            {
                                ds.Tables[0].Rows[i]["F12"] = "";
                            }
                        }
                        else
                        {
                            ds.Tables[0].Rows[i]["F12"] = "";
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize provider's Information", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                    #endregion

                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {
                        if (ds.Tables[0].Rows[i]["F1"].ToString().Trim() == dgv_execl.Rows[a].Cells["Purch.Doc."].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["Purch.Doc."] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["Doc. Date"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Item"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["A"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Short Text.Doc."] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["Quantity"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["To be del."] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["OUn"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["SLoc"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["Vendor/supplying plant"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;

                            break;
                        }
                    }
                    #endregion
                }
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {
                        if (ds.Tables[0].Rows[i]["F1"].ToString().Trim() == dgv_execl.Rows[a].Cells["Purch.Doc."].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["Purch.Doc."] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["Doc. Date"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Item"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["A"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Short Text.Doc."] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["Quantity"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["To be del."] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["OUn"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["SLoc"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["Vendor/supplying plant"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;

                            break;
                        }
                    }
                    #endregion
                }

                progressBar1.Value = 0;
                progressBar1.Visible = false;
                //根据DataGridView的列构造一个新的DataTable
                DataTable tb = new DataTable();
                foreach (DataGridViewColumn dgvc in dgv.Columns)
                {
                    if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                    {
                        DataColumn dc = new DataColumn();
                        dc.ColumnName = dgvc.DataPropertyName;
                        //dc.DataType = dgvc.ValueType;//若需要限制导入时的数据类型则取消注释，前提是DataGridView必须先绑定一个数据源那怕是空的DataTable
                        tb.Columns.Add(dc);
                    }
                }
                ArrayList al = new ArrayList();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = tb.NewRow();
                    dr["consignor"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                    dr["so_no"] = "";
                    dr["so_day"] = str_time;
                    dr["customer_sale_no"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                    string str_supply = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                    string[] aa = str_supply.Split(' ');
                    if (aa.Length > 0)
                    {
                        dr["customer_code"] = aa[0];
                    }
                    else
                    {
                        dr["customer_code"] = "";
                    }
                    dr["original_order_no"] = "";

                    dr["sku"] = ds.Tables[0].Rows[i]["sku"].ToString().Trim();
                    dr["pack_code"] = ds.Tables[0].Rows[i]["pack_code"].ToString().Trim();
                    dr["plan_so_qty_m"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                    dr["order_price"] = 0;
                    dr["order_unit"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                    dr["address"] = "";
                    dr["standby_11"] = "";
                    dr["standby_12"] = "";
                    dr["standby_13"] = "";
                    dr["lot_attribute5"] = "非保税";
                    //dr["address"] = 0;

                    tb.Rows.Add(dr);
                }

                //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                //{


                //    DataRow dr = tb.NewRow();

                //    dr["lot_attribute5"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                //    dr["lot_attribute3"] = "非保税";
                //    dr["order_unit"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                //    string str_supply = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                //    string[] aa = str_supply.Split(' ');
                //    if (aa.Length > 0)
                //    {
                //        dr["supply"] = aa[0];
                //    }
                //    else
                //    {
                //        dr["supply"] = "";
                //    }
                //    dr["in_tax"] = "";
                //    dr["out_tax"] = "";
                //    dr["arrive_plan_day"] = "";
                //    dr["arrive_deadline"] = "";
                //    dr["buyer"] = "";
                //    dr["sku"] = ;
                //    dr["pack_code"] = ds.Tables[0].Rows[i]["pack_code"].ToString().Trim();
                //    dr["order_qty_m"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim().Replace(",", "");
                //    dr["order_qty_m"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                //    dr["present_qty_m"] = 0;
                //    dr["order_price"] = 0;

                //    tb.Rows.Add(dr);
                //}

                DataView DV = tb.DefaultView;
                DV.Sort = "customer_sale_no asc";
                tb = DV.ToTable();
                //在DataGridView中显示导入的数据
                //dgv.DataSource = DV;
                //main.g_class.DataGridViewToExcel2(dgv);


                progressBar1.Visible = false;
                string str_asn_no = "";
                if (tb.Rows.Count > 0)
                {
                    str_asn_no = main.g_class.comm_getaccountno("so_no");
                    tb.Rows[0]["so_no"] = str_asn_no;
                    if (tb.Rows.Count > 1)
                    {
                        for (int i = 0; i < tb.Rows.Count - 1; i++)
                        {
                            if (tb.Rows[i]["customer_sale_no"].ToString().Trim() == tb.Rows[i + 1]["customer_sale_no"].ToString().Trim())
                            {
                                tb.Rows[i + 1]["so_no"] = str_asn_no;
                            }
                            else
                            {
                                str_asn_no = main.g_class.comm_getaccountno("so_no");
                                tb.Rows[i + 1]["so_no"] = str_asn_no;
                            }
                        }
                    }
                }
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    dgv_execl.DataSource = null;
                }
                dgv.DataSource = tb;
                d_count = tb.Rows.Count;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        //Control Products
        public void EcxelToDataGridView_JS(string filePath, DataGridView dgv)
        {
            //根据路径打开一个Excel文件并将数据填充到DataSet中
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            string str_file;

            str_file = cbx_file.Text.Trim();
            if (str_file.Substring(str_file.Length - 1) == "'")
            {
                str_file = str_file.Substring(0, str_file.Length - 1);
            }
            if (str_file.Substring(str_file.Length - 1) != "$")
            {
                str_file = str_file + "$";
            }
            if (str_file.Substring(0, 1) == "'")
            {
                str_file = str_file.Substring(1);
            }
            try
            {
                OleDbDataAdapter myCommand = null;
                DataSet ds = null;
                DataSet ds_supply;
                strExcel = "select  * from  [" + str_file + "]";
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i][0].ToString().Trim() == "货主编码" || ds.Tables[0].Rows[i][0].ToString().Trim() == "" || ds.Tables[0].Rows[i][0].ToString().Trim() == "Catagory")
                    {
                        ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                        i = i - 1;
                    }
                }
                d_sum = ds.Tables[0].Rows.Count;
                DataTable dt_execl = new DataTable();
                dt_execl.Columns.Add("status");
                dt_execl.Columns.Add("Catagory");
                dt_execl.Columns.Add("FICE采购凭证");
                dt_execl.Columns.Add("Material");
                dt_execl.Columns.Add("Part No.");
                dt_execl.Columns.Add("OB");
                dt_execl.Columns.Add("销售办事处");
                dt_execl.Columns.Add("需求日期");
                dt_execl.Columns.Add("SDC销售凭证");
                dt_execl.Columns.Add("单位");
                dt_execl.Columns.Add("Plnt");
                dt_execl.Columns.Add("发货数量");
                dt_execl.Columns.Add("发运要求");
                dt_execl.Columns.Add("客户地址及发运注意事项");
                dt_execl.Columns.Add("项目名称");
                dt_execl.Columns.Add("standby_11");
                dt_execl.Columns.Add("standby_12");

                dgv_execl.DataSource = dt_execl;
                DataSet ds_temp2;
                string str_sql2 = "";
                ds.Tables[0].Columns.Add("sku");
                ds.Tables[0].Columns.Add("pack_code");
                progressBar1.Visible = true;
                progressBar1.Maximum = ds.Tables[0].Rows.Count;
                progressBar1.Value = 0;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    progressBar1.Value = i;
                    #region 如果SKU为空，直接加入错误列表
                    if (ds.Tables[0].Rows[i]["F3"].ToString().Trim() == "")
                    {
                        DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                        dr["Catagory"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                        dr["FICE采购凭证"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                        dr["Material"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                        dr["Part No."] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                        dr["OB"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                        dr["销售办事处"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                        dr["需求日期"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                        dr["SDC销售凭证"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                        dr["单位"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                        dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                        dr["发货数量"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                        dr["发运要求"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                        dr["客户地址及发运注意事项"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                        dr["项目名称"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                        dr["standby_11"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                        dr["standby_12"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();

                        dr["status"] = "缺档";
                        ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                        ds.Tables[0].Rows.RemoveAt(i);
                        i = i - 1;
                        continue;
                    }
                    #endregion

                    #region SKU

                    str_sql2 = "  SELECT *from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='" + ds.Tables[0].Rows[i]["F10"].ToString().Trim() + "' and sku='" + ds.Tables[0].Rows[i]["F3"].ToString().Trim() + "' and main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        if (ds_temp2.Tables[0].Rows.Count <= 0) //说明没有记录  
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["Catagory"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["FICE采购凭证"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["Part No."] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["OB"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["销售办事处"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["需求日期"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["SDC销售凭证"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["单位"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["发货数量"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["发运要求"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["客户地址及发运注意事项"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                            dr["项目名称"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                            dr["standby_11"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                            dr["standby_12"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                        else
                        {
                            ds.Tables[0].Rows[i]["sku"] = ds_temp2.Tables[0].Rows[0]["sku"].ToString().Trim();
                            ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show("查找商品档案失败!" + ee.ToString());
                        return;
                    }

                    #endregion

                    # region 包装编码
                    //根据SKU找出包装

                    str_sql2 = "select * from " + main.g_space + ".mst_pack where inv_org = '" + main.g_org + "' and consignor = '" + ds.Tables[0].Rows[i]["F10"].ToString().Trim() + "' and sku ='" + ds.Tables[0].Rows[i]["sku"].ToString() + "'   and  main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        //显示详细的信息
                        if (ds_temp2.Tables[0].Rows.Count > 0)
                        {
                            //ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                        }
                        else
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["Catagory"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["FICE采购凭证"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["Part No."] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["OB"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["销售办事处"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["需求日期"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["SDC销售凭证"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["单位"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["发货数量"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["发运要求"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["客户地址及发运注意事项"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                            dr["项目名称"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                            dr["standby_11"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                            dr["standby_12"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get pack's Information", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                    #endregion

                    if (ds.Tables[0].Rows[i]["F13"].ToString().Trim() == "")
                    {
                        #region 地址

                        try
                        {
                            if (main.dbtype == "SQL")
                            {
                                str_sql2 = "select business_address from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and customer_flag = '1' and consignor = '" + ds.Tables[0].Rows[i]["F6"].ToString().Trim() + "' order by consignor";
                                ds_supply = main.dbservice.Sql_exec_selectsql(str_sql2);
                            }
                            else
                            {
                                str_sql2 = "select business_address from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and customer_flag = '1'  and consignor = '" + ds.Tables[0].Rows[i]["F6"].ToString().Trim() + "'  order by consignor";
                                ds_supply = main.dbservice.oracle_exec_selectsql(str_sql2);
                            }
                            if (ds_supply.Tables[0].Rows.Count > 0)
                            {
                                ds.Tables[0].Rows[i]["F12"] = ds_supply.Tables[0].Rows[0]["business_address"].ToString();
                            }
                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize provider's Information", main.g_info_dataset) + "!" + ee.ToString());
                            return;
                        }
                        #endregion
                    }


                }
                progressBar1.Visible = false;
                progressBar1.Value = 0;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {
                        if (ds.Tables[0].Rows[i]["F5"].ToString().Trim() == dgv_execl.Rows[a].Cells["OB"].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["Catagory"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["FICE采购凭证"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["Part No."] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["OB"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["销售办事处"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["需求日期"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["SDC销售凭证"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["单位"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["发货数量"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["发运要求"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["客户地址及发运注意事项"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                            dr["项目名称"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                            dr["standby_11"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                            dr["standby_12"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                            dr["status"] = "";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            break;
                        }
                    }
                    #endregion
                }
                //根据DataGridView的列构造一个新的DataTable
                DataTable tb = new DataTable();
                foreach (DataGridViewColumn dgvc in dgv.Columns)
                {

                    if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                    {
                        DataColumn dc = new DataColumn();
                        dc.ColumnName = dgvc.DataPropertyName;
                        //dc.DataType = dgvc.ValueType;//若需要限制导入时的数据类型则取消注释，前提是DataGridView必须先绑定一个数据源那怕是空的DataTable
                        tb.Columns.Add(dc);
                    }
                }
                //根据Excel的行逐一对上面构造的DataTable的列进行赋值           
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = tb.NewRow();
                    dr["consignor"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                    dr["so_no"] = "";
                    dr["so_day"] = str_time;
                    dr["customer_sale_no"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                    dr["customer_code"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                    dr["original_order_no"] = "";
                    dr["sku"] = ds.Tables[0].Rows[i]["sku"].ToString().Trim();
                    dr["pack_code"] = ds.Tables[0].Rows[i]["pack_code"].ToString().Trim();
                    dr["plan_so_qty_m"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                    dr["order_price"] = 0;
                    dr["address"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                    dr["order_unit"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                    dr["project_name"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                    dr["standby_11"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                    dr["standby_12"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                    dr["standby_13"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                    dr["standby_3"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                    dr["rush_flag"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                    tb.Rows.Add(dr);
                }
                DataView DV = tb.DefaultView;
                DV.Sort = "customer_sale_no asc";
                tb = DV.ToTable();
                string str_so_no = "";
                if (tb.Rows.Count > 0)
                {
                    str_so_no = main.g_class.comm_getaccountno("so_no");
                    tb.Rows[0]["so_no"] = str_so_no;
                    if (tb.Rows.Count > 1)
                    {
                        for (int i = 0; i < tb.Rows.Count - 1; i++)
                        {
                            if (tb.Rows[i]["customer_sale_no"].ToString().Trim() == tb.Rows[i + 1]["customer_sale_no"].ToString().Trim() &&
                                tb.Rows[i]["address"].ToString().Trim() == tb.Rows[i + 1]["address"].ToString().Trim())
                            {
                                tb.Rows[i + 1]["so_no"] = str_so_no;
                            }
                            else
                            {
                                str_so_no = main.g_class.comm_getaccountno("so_no");
                                tb.Rows[i + 1]["so_no"] = str_so_no;
                            }
                        }
                    }
                }

                //在DataGridView中显示导入的数据
                dgv.DataSource = tb;
                d_count = tb.Rows.Count;
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    dgv_execl.DataSource = null;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }

        //Service Parts
        public void EcxelToDataGridView_JS2(string filePath, DataGridView dgv)
        {
            //根据路径打开一个Excel文件并将数据填充到DataSet中
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            string str_file;

            str_file = cbx_file.Text.Trim();
            if (str_file.Substring(str_file.Length - 1) == "'")
            {
                str_file = str_file.Substring(0, str_file.Length - 1);
            }
            if (str_file.Substring(str_file.Length - 1) != "$")
            {
                str_file = str_file + "$";
            }
            if (str_file.Substring(0, 1) == "'")
            {
                str_file = str_file.Substring(1);
            }
            try
            {
                OleDbDataAdapter myCommand = null;
                DataSet ds = null;
                strExcel = "select  * from  [" + str_file + "]";
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["F4"].ToString().Trim() == "货主编码" || ds.Tables[0].Rows[i]["F4"].ToString().Trim() == "" || ds.Tables[0].Rows[i][0].ToString().Trim() == "AAA")
                    {
                        ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                        i = i - 1;
                    }

                }
                d_sum = ds.Tables[0].Rows.Count;
                DataTable dt_execl = new DataTable();
                dt_execl.Columns.Add("status");
                dt_execl.Columns.Add("AAA");
                dt_execl.Columns.Add("Item No.");
                dt_execl.Columns.Add("Customer PO");
                dt_execl.Columns.Add("Material");
                dt_execl.Columns.Add("Part No.");
                dt_execl.Columns.Add("Part Description");
                dt_execl.Columns.Add("Sloc");
                dt_execl.Columns.Add("Office");
                dt_execl.Columns.Add("Doc. Date");
                dt_execl.Columns.Add("Plnt");
                dt_execl.Columns.Add("Sales Doc.");
                dt_execl.Columns.Add("SU");
                dt_execl.Columns.Add("实发数量");
                dt_execl.Columns.Add("发运要求");
                dt_execl.Columns.Add("紧急");
                dt_execl.Columns.Add("standby_11");
                dt_execl.Columns.Add("standby_12");
                dgv_execl.DataSource = dt_execl;
                DataSet ds_temp2;
                string str_sql2 = "";
                ds.Tables[0].Columns.Add("sku");
                ds.Tables[0].Columns.Add("pack_code");
                progressBar1.Visible = true;
                progressBar1.Maximum = ds.Tables[0].Rows.Count;
                progressBar1.Value = 0;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    progressBar1.Value = i;
                    #region 如果SKU为空，直接加入错误列表
                    if (ds.Tables[0].Rows[i]["F3"].ToString().Trim() == "")
                    {
                        DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                        dr["AAA"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                        dr["Item No."] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                        dr["Customer PO"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                        dr["Material"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                        dr["Part No."] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                        dr["Part Description"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                        dr["Sloc"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                        dr["Office"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                        dr["Doc. Date"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                        dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                        dr["Sales Doc."] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                        dr["SU"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                        dr["实发数量"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                        dr["发运要求"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                        dr["紧急"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                        dr["standby_11"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                        dr["standby_12"] = ds.Tables[0].Rows[i]["F17"].ToString().Trim();
                        dr["status"] = "缺档";
                        ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                        ds.Tables[0].Rows.RemoveAt(i);
                        i = i - 1;
                        continue;
                    }
                    #endregion

                    #region SKU

                    str_sql2 = "  SELECT *from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='" + ds.Tables[0].Rows[i]["F10"].ToString().Trim() + "' and sku='" + ds.Tables[0].Rows[i]["F4"].ToString().Trim() + "' and main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        if (ds_temp2.Tables[0].Rows.Count <= 0) //说明没有记录  
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["AAA"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["Item No."] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Customer PO"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["Part No."] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Part Description"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["Sloc"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["Office"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["Doc. Date"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["Sales Doc."] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["SU"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["实发数量"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                            dr["发运要求"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                            dr["紧急"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                            dr["standby_11"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                            dr["standby_12"] = ds.Tables[0].Rows[i]["F17"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                        else
                        {
                            ds.Tables[0].Rows[i]["sku"] = ds_temp2.Tables[0].Rows[0]["sku"].ToString().Trim();
                            ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show("查找商品档案失败!" + ee.ToString());
                        return;
                    }

                    #endregion

                    # region 包装编码
                    //根据SKU找出包装

                    str_sql2 = "select * from " + main.g_space + ".mst_pack where inv_org = '" + main.g_org + "' and consignor = '" + ds.Tables[0].Rows[i]["F10"].ToString().Trim() + "' and sku ='" + ds.Tables[0].Rows[i]["sku"].ToString() + "'   and  main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        //显示详细的信息
                        if (ds_temp2.Tables[0].Rows.Count > 0)
                        {
                            //ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                        }
                        else
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["AAA"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["Item No."] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Customer PO"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["Part No."] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Part Description"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["Sloc"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["Office"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["Doc. Date"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["Sales Doc."] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["SU"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["实发数量"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                            dr["发运要求"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                            dr["紧急"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                            dr["standby_11"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                            dr["standby_12"] = ds.Tables[0].Rows[i]["F17"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get pack's Information", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                    #endregion

                    if (ds.Tables[0].Rows[i]["F14"].ToString().Trim() == "")
                    {
                        //#region 地址

                        //try
                        //{


                        //    if (main.dbtype == "SQL")
                        //    {
                        //        str_sql2 = "select business_address from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and customer_flag = '1' and consignor = '" + ds.Tables[0].Rows[i]["F7"].ToString().Trim() + "' order by consignor";
                        //        ds_supply = main.dbservice.Sql_exec_selectsql(str_sql2);
                        //    }
                        //    else
                        //    {
                        //        str_sql2 = "select business_address from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and customer_flag = '1'  and consignor = '" + ds.Tables[0].Rows[i]["F7"].ToString().Trim() + "'  order by consignor";
                        //        ds_supply = main.dbservice.oracle_exec_selectsql(str_sql2);
                        //    }
                        //    if (ds_supply.Tables[0].Rows.Count > 0)
                        //    {
                        //        ds.Tables[0].Rows[i]["F14"] = ds_supply.Tables[0].Rows[0]["business_address"].ToString();
                        //    }
                        //}
                        //catch (System.Exception ee)
                        //{
                        //    MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize provider's Information", main.g_info_dataset) + "!" + ee.ToString());
                        //    return;
                        //}
                        //#endregion
                    }


                }
                progressBar1.Visible = false;
                progressBar1.Value = 0;

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {
                        if (ds.Tables[0].Rows[i]["F11"].ToString().Trim() == dgv_execl.Rows[a].Cells["Sales Doc."].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["AAA"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["Item No."] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["Customer PO"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["Material"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["Part No."] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Part Description"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["Sloc"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["Office"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["Doc. Date"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["Plnt"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["Sales Doc."] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["SU"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["实发数量"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                            dr["发运要求"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                            dr["紧急"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                            dr["standby_11"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                            dr["standby_12"] = ds.Tables[0].Rows[i]["F17"].ToString().Trim();
                            dr["status"] = "";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;

                            break;
                        }
                    }
                    #endregion
                }
                //根据DataGridView的列构造一个新的DataTable
                DataTable tb = new DataTable();
                foreach (DataGridViewColumn dgvc in dgv.Columns)
                {
                    if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                    {
                        DataColumn dc = new DataColumn();
                        dc.ColumnName = dgvc.DataPropertyName;
                        //dc.DataType = dgvc.ValueType;//若需要限制导入时的数据类型则取消注释，前提是DataGridView必须先绑定一个数据源那怕是空的DataTable
                        tb.Columns.Add(dc);
                    }
                }

                //根据Excel的行逐一对上面构造的DataTable的列进行赋值

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = tb.NewRow();
                    dr["consignor"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                    dr["so_no"] = "";
                    dr["so_day"] = str_time;
                    dr["customer_sale_no"] = "";
                    dr["customer_code"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                    dr["original_order_no"] = "";

                    dr["sku"] = ds.Tables[0].Rows[i]["sku"].ToString().Trim();
                    dr["pack_code"] = ds.Tables[0].Rows[i]["pack_code"].ToString().Trim();
                    dr["plan_so_qty_m"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                    dr["order_price"] = 0;
                    dr["order_unit"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                    dr["address"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                    dr["standby_11"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                    dr["standby_12"] = ds.Tables[0].Rows[i]["F17"].ToString().Trim();
                    dr["standby_13"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                    dr["standby_2"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                    dr["standby_3"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                    dr["rush_flag"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();

                    tb.Rows.Add(dr);
                }

                DataView DV = tb.DefaultView;
                DV.Sort = "customer_code,address ";
                tb = DV.ToTable();
                string str_so_no = "";
                if (tb.Rows.Count > 0)
                {
                    str_so_no = main.g_class.comm_getaccountno("so_no");
                    tb.Rows[0]["so_no"] = str_so_no;
                    if (tb.Rows.Count > 1)
                    {
                        for (int i = 0; i < tb.Rows.Count - 1; i++)
                        {
                            if (tb.Rows[i]["customer_code"].ToString().Trim() == tb.Rows[i + 1]["customer_code"].ToString().Trim() &&
                                tb.Rows[i]["address"].ToString().Trim() == tb.Rows[i + 1]["address"].ToString().Trim())
                            {
                                tb.Rows[i + 1]["so_no"] = str_so_no;
                            }
                            else
                            {
                                str_so_no = main.g_class.comm_getaccountno("so_no");
                                tb.Rows[i + 1]["so_no"] = str_so_no;
                            }
                        }
                    }
                }

                //在DataGridView中显示导入的数据
                dgv.DataSource = tb;
                d_count = tb.Rows.Count;
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    dgv_execl.DataSource = null;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }

        //转口出货单
        public void EcxelToDataGridView_JS3(string filePath, DataGridView dgv)
        {
            //根据路径打开一个Excel文件并将数据填充到DataSet中
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            string str_file;

            str_file = cbx_file.Text.Trim();
            if (str_file.Substring(str_file.Length - 1) == "'")
            {
                str_file = str_file.Substring(0, str_file.Length - 1);
            }
            if (str_file.Substring(str_file.Length - 1) != "$")
            {
                str_file = str_file + "$";
            }
            if (str_file.Substring(0, 1) == "'")
            {
                str_file = str_file.Substring(1);
            }
            try
            {
                OleDbDataAdapter myCommand = null;
                DataSet ds = null;
                strExcel = "select  * from  [" + str_file + "]";
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["F1"].ToString().Trim() == "" || ds.Tables[0].Rows[i]["F1"].ToString().Trim() == "英文描述" || ds.Tables[0].Rows[i]["F1"].ToString().Trim() == "(忽略)")
                    {
                        ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                        i = i - 1;
                    }

                }
                DataTable dt_sku = new DataTable();
                dt_sku.Columns.Add("货主");
                dt_sku.Columns.Add("SAP");
                dt_sku.Columns.Add("原因");
                d_sum = ds.Tables[0].Rows.Count;
                DataTable dt_execl = new DataTable();
                dt_execl.Columns.Add("status");
                dt_execl.Columns.Add("英文描述");
                dt_execl.Columns.Add("件数");
                dt_execl.Columns.Add("单位");
                dt_execl.Columns.Add("总价");
                dt_execl.Columns.Add("SAP#");
                dt_execl.Columns.Add("保税状态");
                dt_execl.Columns.Add("SOLD TO");
                dt_execl.Columns.Add("SHIP TO");
                dt_execl.Columns.Add("PO#");
                dt_execl.Columns.Add("SO#");               
                dt_execl.Columns.Add("货主");
                dt_execl.Columns.Add("进仓单号");
                dt_execl.Columns.Add("运输方式");
                dt_execl.Columns.Add("OB NO.");
                dt_execl.Columns.Add("Export Number");

                dgv_execl.DataSource = dt_execl;
                DataSet ds_temp2;
                decimal d_gross_weight = 0;
                string str_sql2 = "";
                ds.Tables[0].Columns.Add("sku");
                ds.Tables[0].Columns.Add("pack_code");
                //ds.Tables[0].Columns.Add("sold_to");
                //ds.Tables[0].Columns.Add("ship_to");
                //ds.Tables[0].Columns.Add("CTY");
                progressBar1.Visible = true;
                progressBar1.Maximum = ds.Tables[0].Rows.Count;
                progressBar1.Value = 0;

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    progressBar1.Value = i;
                    #region 如果SKU为空，直接加入错误列表
                    if (ds.Tables[0].Rows[i]["F5"].ToString().Trim() == "")
                    {
                        DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                        dr["英文描述"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                        dr["件数"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                        dr["单位"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                        dr["总价"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                        dr["SAP#"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                        dr["保税状态"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                        dr["SOLD TO"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                        dr["SHIP TO"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                        dr["PO#"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                        dr["SO#"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();                     
                        dr["货主"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                        dr["进仓单号"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                        dr["运输方式"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                        dr["OB NO."] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                        dr["Export Number"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                        dr["status"] = "缺档";
                        ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                        ds.Tables[0].Rows.RemoveAt(i);
                        i = i - 1;
                        continue;
                    }
                    #endregion

                    #region SKU

                    str_sql2 = "  SELECT *from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='" + ds.Tables[0].Rows[i]["F11"].ToString().Trim() + "' and sku='" + ds.Tables[0].Rows[i]["F5"].ToString().Trim() + "' and main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        if (ds_temp2.Tables[0].Rows.Count <= 0) //说明没有记录  
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["英文描述"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["件数"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["单位"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["总价"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["SAP#"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["保税状态"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["SOLD TO"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["SHIP TO"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["PO#"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["SO#"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["货主"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["进仓单号"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["运输方式"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                            dr["OB NO."] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                            dr["Export Number"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                            dr["status"] = "缺商品档案";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                        else
                        {
                            d_gross_weight = Convert.ToDecimal(ds_temp2.Tables[0].Rows[0]["gross_weight"].ToString().Trim());
                            if (d_gross_weight == 0)
                            {
                                DataRow dr = dt_sku.NewRow();
                                dr["货主"] = ds_temp2.Tables[0].Rows[0]["consignor"].ToString().Trim();
                                dr["SAP"] = ds_temp2.Tables[0].Rows[0]["sku"].ToString().Trim();
                                dr["原因"] = "净重为0";
                                dt_sku.Rows.Add(dr);
                            }
                            if (ds_temp2.Tables[0].Rows[0]["mf_name"].ToString().Trim() == ""
                                || ds_temp2.Tables[0].Rows[0]["mf_co"].ToString().Trim() == ""
                                || ds_temp2.Tables[0].Rows[0]["mf_unit"].ToString().Trim() == ""
                                || ds_temp2.Tables[0].Rows[0]["mf_taxno"].ToString().Trim() == "")
                            {
                                DataRow dr = dt_sku.NewRow();
                                dr["货主"] = ds_temp2.Tables[0].Rows[0]["consignor"].ToString().Trim();
                                dr["SAP"] = ds_temp2.Tables[0].Rows[0]["sku"].ToString().Trim();
                                dr["原因"] = "MF档案不全,请补全.";
                                dt_sku.Rows.Add(dr);
                            }
                            ds.Tables[0].Rows[i]["sku"] = ds_temp2.Tables[0].Rows[0]["sku"].ToString().Trim();
                            ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show("查找商品档案失败!" + ee.ToString());
                        return;
                    }

                    #endregion

                    # region 包装编码
                    //根据SKU找出包装

                    str_sql2 = "select * from " + main.g_space + ".mst_pack where inv_org = '" + main.g_org + "' and consignor = '" + ds.Tables[0].Rows[i]["F11"].ToString().Trim() + "' and sku ='" + ds.Tables[0].Rows[i]["F5"].ToString() + "'   and  main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        //显示详细的信息
                        if (ds_temp2.Tables[0].Rows.Count > 0)
                        {
                            //ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                        }
                        else
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["英文描述"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["件数"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["单位"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["总价"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["SAP#"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["保税状态"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["SOLD TO"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["SHIP TO"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["PO#"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["SO#"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["货主"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["进仓单号"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["运输方式"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                            dr["OB NO."] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                            dr["Export Number"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get pack's Information", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                    #endregion

                    #region ship_to

                    //try
                    //{

                    //    DataSet ds_supply;
                    //    if (main.dbtype == "SQL")
                    //    {
                    //        str_sql2 = "select * from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and customer_flag = '1' and consignor = '" + ds.Tables[0].Rows[i]["F10"].ToString().Trim() + "' ";
                    //        ds_supply = main.dbservice.Sql_exec_selectsql(str_sql2);
                    //    }
                    //    else
                    //    {
                    //        str_sql2 = "select * from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and customer_flag = '1'  and consignor = '" + ds.Tables[0].Rows[i]["F10"].ToString().Trim() + "' ";
                    //        ds_supply = main.dbservice.oracle_exec_selectsql(str_sql2);
                    //    }
                    //    if (ds_supply.Tables[0].Rows.Count > 0)
                    //    {
                    //        ds.Tables[0].Rows[i]["ship_to"] = ds_supply.Tables[0].Rows[0]["consignor_name"].ToString();
                    //        ds.Tables[0].Rows[i]["CTY"] = ds_supply.Tables[0].Rows[0]["city"].ToString();
                    //    }
                    //    else
                    //    {
                    //        DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                    //        dr["英文描述"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                    //        dr["件数"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                    //        dr["单位"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                    //        dr["总价"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                    //        dr["SAP#"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                    //        dr["保税状态"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                    //        dr["PO#"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                    //        dr["SO#"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                    //        dr["SOLD TO"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                    //        dr["SHIP TO"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                    //        dr["货主"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                    //        dr["进仓单号"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                    //        dr["运输方式"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                    //        dr["OB NO."] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                    //        dr["Export Number"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                    //        dr["status"] = "缺客户档案";
                    //        ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                    //        ds.Tables[0].Rows.RemoveAt(i);
                    //        i = i - 1;
                    //        continue;
                    //    }
                    //}
                    //catch (System.Exception ee)
                    //{
                    //    MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize provider's Information", main.g_info_dataset) + "!" + ee.ToString());
                    //    return;
                    //}
                    #endregion

                    #region sold_to

                    //try
                    //{

                    //    DataSet ds_supply;
                    //    if (main.dbtype == "SQL")
                    //    {
                    //        str_sql2 = "select * from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and customer_flag = '1' and consignor = '" + ds.Tables[0].Rows[i]["F10"].ToString().Trim() + "' ";
                    //        ds_supply = main.dbservice.Sql_exec_selectsql(str_sql2);
                    //    }
                    //    else
                    //    {
                    //        str_sql2 = "select * from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and customer_flag = '1'  and consignor = '" + ds.Tables[0].Rows[i]["F10"].ToString().Trim() + "' ";
                    //        ds_supply = main.dbservice.oracle_exec_selectsql(str_sql2);
                    //    }
                    //    if (ds_supply.Tables[0].Rows.Count > 0)
                    //    {
                    //        ds.Tables[0].Rows[i]["sold_to"] = ds_supply.Tables[0].Rows[0]["consignor_name"].ToString();
                    //    }
                    //    else
                    //    {
                    //        DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                    //        dr["英文描述"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                    //        dr["件数"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                    //        dr["单位"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                    //        dr["总价"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                    //        dr["SAP#"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                    //        dr["保税状态"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                    //        dr["PO#"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                    //        dr["SO#"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                    //        dr["SOLD TO"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                    //        dr["SHIP TO"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                    //        dr["货主"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                    //        dr["进仓单号"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                    //        dr["运输方式"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                    //        dr["OB NO."] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                    //        dr["Export Number"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                    //        dr["status"] = "缺客户档案";
                    //        ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                    //        ds.Tables[0].Rows.RemoveAt(i);
                    //        i = i - 1;
                    //        continue;
                    //    }
                    //}
                    //catch (System.Exception ee)
                    //{
                    //    MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize provider's Information", main.g_info_dataset) + "!" + ee.ToString());
                    //    return;
                    //}
                    #endregion

                }
                progressBar1.Visible = false;
                progressBar1.Value = 0;

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {
                        if (ds.Tables[0].Rows[i]["F8"].ToString().Trim() == dgv_execl.Rows[a].Cells["SO#"].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["英文描述"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                            dr["件数"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                            dr["单位"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                            dr["总价"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                            dr["SAP#"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["保税状态"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                            dr["SOLD TO"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                            dr["SHIP TO"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["PO#"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["SO#"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();                           
                            dr["货主"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["进仓单号"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["运输方式"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                            dr["OB NO."] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                            dr["Export Number"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                            dr["status"] = "";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;

                            break;
                        }
                    }
                    #endregion
                }
                //根据DataGridView的列构造一个新的DataTable
                DataTable tb = new DataTable();
                foreach (DataGridViewColumn dgvc in dgv.Columns)
                {

                    if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                    {
                        DataColumn dc = new DataColumn();
                        dc.ColumnName = dgvc.DataPropertyName;
                        //dc.DataType = dgvc.ValueType;//若需要限制导入时的数据类型则取消注释，前提是DataGridView必须先绑定一个数据源那怕是空的DataTable
                        tb.Columns.Add(dc);
                    }
                }

                //根据Excel的行逐一对上面构造的DataTable的列进行赋值
                decimal d_order_price = 0, d_qty = 0;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = tb.NewRow();
                    d_order_price = Convert.ToDecimal(ds.Tables[0].Rows[i]["F4"].ToString().Trim());
                    d_qty=Convert.ToDecimal(ds.Tables[0].Rows[i]["F2"].ToString().Trim());
                    d_order_price=Math.Round(d_order_price/d_qty,4);
                    dr["consignor"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                    dr["so_no"] = "";
                    dr["so_day"] = str_time;
                    dr["customer_sale_no"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                    //dr["customer_code"] = "";
                    dr["customer_code"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                    dr["customer_name"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                    dr["original_order_no"] = "";
                    dr["receiver"] = "";
                    dr["sku"] = ds.Tables[0].Rows[i]["sku"].ToString().Trim();
                    dr["pack_code"] = ds.Tables[0].Rows[i]["pack_code"].ToString().Trim();
                    dr["plan_so_qty_m"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                    dr["order_price"] = d_order_price.ToString().Trim();
                    dr["order_unit"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                    dr["address"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                    if (ds.Tables[0].Columns.Contains("F13"))
                    {
                        dr["standby_11"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                    }
                    else
                    {
                        dr["standby_11"] = "";
                    }
                    if (ds.Tables[0].Rows[i]["F6"].ToString().Trim() == "B")
                    {
                        dr["lot_attribute3"] = "保税";
                    }
                    else
                    {
                        dr["lot_attribute3"] = "非保税";
                    }
                    dr["standby_13"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                    dr["standby_14"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();

                    dr["area_code"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                    dr["standby_2"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                    dr["standby_3"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                    //dr["address"] = 0;

                    tb.Rows.Add(dr);
                }

                DataView DV = tb.DefaultView;
                DV.Sort = "customer_sale_no asc";
                tb = DV.ToTable();
                string str_so_no = "";
                if (tb.Rows.Count > 0)
                {
                    str_so_no = main.g_class.comm_getaccountno("so_no");
                    tb.Rows[0]["so_no"] = str_so_no;
                    if (tb.Rows.Count > 1)
                    {
                        for (int i = 0; i < tb.Rows.Count; i++)
                        {
                            tb.Rows[i]["so_no"] = str_so_no;
                        }
                        //for (int i = 0; i < tb.Rows.Count - 1; i++)
                        //{
                        //    if (tb.Rows[i]["customer_sale_no"].ToString().Trim() == tb.Rows[i + 1]["customer_sale_no"].ToString().Trim() &&
                        //        tb.Rows[i]["address"].ToString().Trim() == tb.Rows[i + 1]["address"].ToString().Trim())
                        //    {
                        //        tb.Rows[i + 1]["so_no"] = str_so_no;
                        //    }
                        //    else
                        //    {
                        //        str_so_no = main.g_class.comm_getaccountno("so_no");
                        //        tb.Rows[i + 1]["so_no"] = str_so_no;
                        //    }
                        //}
                    }
                }

                //在DataGridView中显示导入的数据
                dgv.DataSource = tb;
                d_count = tb.Rows.Count;
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    dgv_execl.DataSource = null;
                }
                if (dt_sku.Rows.Count > 0)
                {
                     
                        int irow = 1;
                        //int irowtmp = 8;
                        excel = new ExcelBase();
                        be = null;

                        be = new ExcelBE(irow, 1, "货主", "A" + irow.ToString(), "", "", true, 20, "n", null, false, 2, 11, true);
                        excel.InsertData(be);

                        be = new ExcelBE(irow, 2, "SAP", "B" + irow.ToString(), "", "", true, 18, "n", null, false, 2, 11, true);
                        excel.InsertData(be);

                        be = new ExcelBE(irow, 3, "原因", "B" + irow.ToString(), "", "", true, 18, "n", null, false, 2, 11, true);
                        excel.InsertData(be);

                        for (int i = 0; i < dt_sku.Rows.Count; i++)
                        {


                            irow++;
                            be = new ExcelBE(irow, 1, dt_sku.Rows[i]["货主"].ToString().Trim(), "A" + irow.ToString(), "A" + irow.ToString(), "", true, 20, "n", null, false, 2, 11, true);
                            excel.InsertData(be);

                            be = new ExcelBE(irow, 2, dt_sku.Rows[i]["SAP"].ToString().Trim(), "B" + irow.ToString(), "B" + irow.ToString(), "", true, 18, "n", null, false, 2, 11, true);
                            excel.InsertData(be);
                            be = new ExcelBE(irow, 3, dt_sku.Rows[i]["原因"].ToString().Trim(), "C" + irow.ToString(), "C" + irow.ToString(), "", true, 18, "n", null, false, 2, 11, true);
                            excel.InsertData(be);

                        }

                        excel.setExcelVisible(true);

                    }
                
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }

        //sh office
        public void EcxelToDataGridView_JS4(string filePath, DataGridView dgv)
        {
            //根据路径打开一个Excel文件并将数据填充到DataSet中
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            string str_file;

            str_file = cbx_file.Text.Trim();
            if (str_file.Substring(str_file.Length - 1) == "'")
            {
                str_file = str_file.Substring(0, str_file.Length - 1);
            }
            if (str_file.Substring(str_file.Length - 1) != "$")
            {
                str_file = str_file + "$";
            }
            if (str_file.Substring(0, 1) == "'")
            {
                str_file = str_file.Substring(1);
            }
            try
            {
                OleDbDataAdapter myCommand = null;
                DataSet ds = null;
                strExcel = "select  * from  [" + str_file + "]";
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");
                conn.Close();
                //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                //{
                //    if (ds.Tables[0].Rows[i]["No."].ToString().Trim() == "No." || ds.Tables[0].Rows[i]["No."].ToString().Trim() == "No" || ds.Tables[0].Rows[i]["No."].ToString().Trim() == "No#" || ds.Tables[0].Rows[i]["No."].ToString().Trim() == "No#")
                //    {
                //ds.Tables[0].Rows.RemoveAt(0);
                //        i = i - 1;
                //    }

                //}
                d_sum = ds.Tables[0].Rows.Count;
                DataTable dt_execl = new DataTable();
                dt_execl.Columns.Add("status");
                dt_execl.Columns.Add("Material_物料");
                dt_execl.Columns.Add("Sloc_仓库号");
                dt_execl.Columns.Add("SDC Sales Doc#_SDC销售单号");
                dt_execl.Columns.Add("SU_单位");
                dt_execl.Columns.Add("Order Qty_到货数量");
                dt_execl.Columns.Add("SAP OB#            系统发运单号");
                dt_execl.Columns.Add("快递");
                dt_execl.Columns.Add("公路");

                dgv_execl.DataSource = dt_execl;
                DataSet ds_temp2;
                string str_sql2 = "";
                ds.Tables[0].Columns.Add("sku");
                ds.Tables[0].Columns.Add("pack_code");
                progressBar1.Visible = true;
                progressBar1.Maximum = ds.Tables[0].Rows.Count;
                progressBar1.Value = 0;

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    progressBar1.Value = i;


                    #region SKU

                    str_sql2 = "  SELECT *from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='" + ds.Tables[0].Rows[i]["F8"].ToString().Trim() + "' and sku='" + ds.Tables[0].Rows[i]["F5"].ToString().Trim() + "' and main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        if (ds_temp2.Tables[0].Rows.Count <= 0) //说明没有记录  
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["Material_物料"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Sloc_仓库号"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["SDC Sales Doc#_SDC销售单号"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["SU_单位"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["Order Qty_到货数量"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                            dr["SAP OB#            系统发运单号"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                            dr["快递"] = ds.Tables[0].Rows[i]["F25"].ToString().Trim();
                            dr["公路"] = ds.Tables[0].Rows[i]["F26"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                        else
                        {
                            ds.Tables[0].Rows[i]["sku"] = ds_temp2.Tables[0].Rows[0]["sku"].ToString().Trim();
                            ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show("查找商品档案失败!" + ee.ToString());
                        return;
                    }

                    #endregion

                    # region 包装编码
                    //根据SKU找出包装

                    str_sql2 = "select * from " + main.g_space + ".mst_pack where inv_org = '" + main.g_org + "' and consignor = '" + ds.Tables[0].Rows[i]["F8"].ToString().Trim() + "' and sku ='" + ds.Tables[0].Rows[i]["sku"].ToString() + "'   and  main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        //显示详细的信息
                        if (ds_temp2.Tables[0].Rows.Count > 0)
                        {
                            //ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                        }
                        else
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["Material_物料"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Sloc_仓库号"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["SDC Sales Doc#_SDC销售单号"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["SU_单位"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["Order Qty_到货数量"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                            dr["SAP OB#            系统发运单号"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                            dr["快递"] = ds.Tables[0].Rows[i]["F25"].ToString().Trim();
                            dr["公路"] = ds.Tables[0].Rows[i]["F26"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get pack's Information", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                    #endregion

                }
                progressBar1.Visible = false;
                progressBar1.Value = 0;

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {


                        if (ds.Tables[0].Rows[i]["F18"].ToString().Trim() == dgv_execl.Rows[a].Cells["SAP OB#            系统发运单号"].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["Material_物料"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                            dr["Sloc_仓库号"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                            dr["SDC Sales Doc#_SDC销售单号"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                            dr["SU_单位"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                            dr["Order Qty_到货数量"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                            dr["SAP OB#            系统发运单号"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                            dr["快递"] = ds.Tables[0].Rows[i]["F25"].ToString().Trim();
                            dr["公路"] = ds.Tables[0].Rows[i]["F26"].ToString().Trim();
                            dr["status"] = "";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;

                            break;
                        }
                    }
                    #endregion
                }
                //根据DataGridView的列构造一个新的DataTable
                DataTable tb = new DataTable();
                foreach (DataGridViewColumn dgvc in dgv.Columns)
                {

                    if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                    {
                        DataColumn dc = new DataColumn();
                        dc.ColumnName = dgvc.DataPropertyName;
                        //dc.DataType = dgvc.ValueType;//若需要限制导入时的数据类型则取消注释，前提是DataGridView必须先绑定一个数据源那怕是空的DataTable
                        tb.Columns.Add(dc);
                    }
                }

                //根据Excel的行逐一对上面构造的DataTable的列进行赋值

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = tb.NewRow();
                    dr["consignor"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                    dr["so_no"] = "";
                    dr["so_day"] = str_time;
                    dr["customer_sale_no"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                    dr["customer_code"] = "";
                    dr["original_order_no"] = "";

                    dr["sku"] = ds.Tables[0].Rows[i]["sku"].ToString().Trim();
                    dr["pack_code"] = ds.Tables[0].Rows[i]["pack_code"].ToString().Trim();
                    dr["plan_so_qty_m"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                    dr["order_price"] = 0;
                    dr["order_unit"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                    dr["address"] = "";
                    dr["standby_11"] = ds.Tables[0].Rows[i]["F25"].ToString().Trim();
                    dr["standby_12"] = ds.Tables[0].Rows[i]["F26"].ToString().Trim();
                    dr["standby_13"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                    dr["standby_3"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                    dr["address"] = ds.Tables[0].Rows[i]["F24"].ToString().Trim();

                    tb.Rows.Add(dr);
                }

                DataView DV = tb.DefaultView;
                DV.Sort = "customer_sale_no,address asc";
                tb = DV.ToTable();
                string str_so_no = "";
                if (tb.Rows.Count > 0)
                {
                    str_so_no = main.g_class.comm_getaccountno("so_no");
                    tb.Rows[0]["so_no"] = str_so_no;
                    if (tb.Rows.Count > 1)
                    {
                        for (int i = 0; i < tb.Rows.Count - 1; i++)
                        {
                            if (tb.Rows[i]["customer_sale_no"].ToString().Trim() == tb.Rows[i + 1]["customer_sale_no"].ToString().Trim() &&
                                tb.Rows[i]["address"].ToString().Trim() == tb.Rows[i + 1]["address"].ToString().Trim())
                            {
                                tb.Rows[i + 1]["so_no"] = str_so_no;
                            }
                            else
                            {
                                str_so_no = main.g_class.comm_getaccountno("so_no");
                                tb.Rows[i + 1]["so_no"] = str_so_no;
                            }
                        }
                    }
                }

                //在DataGridView中显示导入的数据
                dgv.DataSource = tb;
                d_count = tb.Rows.Count;
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    dgv_execl.DataSource = null;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }

        public void EcxelToDataGridView_WXJS(string filePath, DataGridView dgv)
        {
            //根据路径打开一个Excel文件并将数据填充到DataSet中
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            string str_file;

            str_file = cbx_file.Text.Trim();
            if (str_file.Substring(str_file.Length - 1) == "'")
            {
                str_file = str_file.Substring(0, str_file.Length - 1);
            }
            if (str_file.Substring(str_file.Length - 1) != "$")
            {
                str_file = str_file + "$";
            }
            if (str_file.Substring(0, 1) == "'")
            {
                str_file = str_file.Substring(1);
            }
            try
            {
                OleDbDataAdapter myCommand = null;
                DataSet ds = null;
                strExcel = "select  * from  [" + str_file + "]";
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");
                conn.Close();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["F1"].ToString().Trim() == "需求时间" || ds.Tables[0].Rows[i]["F1"].ToString().Trim() == "工程项目")
                    {
                        ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                        i = i - 1;
                    }
                }
                d_sum = ds.Tables[0].Rows.Count;
                DataTable dt_execl = new DataTable();
                dt_execl.Columns.Add("status");
                dt_execl.Columns.Add("MO");
                dt_execl.Columns.Add("物料");

                dgv_execl.DataSource = dt_execl;
                DataSet ds_temp2;
                string str_sql2 = "";
                ds.Tables[0].Columns.Add("sku");
                ds.Tables[0].Columns.Add("pack_code");
                ds.Tables[0].Columns.Add("order_unit");
                progressBar1.Visible = true;
                progressBar1.Maximum = ds.Tables[0].Rows.Count;
                progressBar1.Value = 0;
                //DataSet ds_supply;
                //int i_count = 0;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    // i_count = 0;
                    progressBar1.Value = i;
                    #region SKU

                    str_sql2 = "  SELECT *from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='" + ds.Tables[0].Rows[i]["F16"].ToString().Trim() + "' and sku='" + ds.Tables[0].Rows[i]["F10"].ToString().Trim() + "'  and main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        if (ds_temp2.Tables[0].Rows.Count <= 0) //说明没有记录  
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();

                            dr["MO"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                            dr["物料"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                        else
                        {
                            ds.Tables[0].Rows[i]["sku"] = ds_temp2.Tables[0].Rows[0]["sku"].ToString().Trim();
                            ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                            ds.Tables[0].Rows[i]["order_unit"] = ds_temp2.Tables[0].Rows[0]["main_unit"].ToString().Trim();

                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show("查找商品档案失败!" + ee.ToString());
                        return;
                    }

                    #endregion

                    //#region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    //for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    //{
                    //    if (ds.Tables[0].Rows[i]["F9"].ToString().Trim() == dgv_execl.Rows[a].Cells["MO"].Value.ToString().Trim())
                    //    {
                    //        DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                    //        dr["MO"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                    //        dr["物料"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();                
                    //        dr["status"] = "";
                    //        ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                    //        ds.Tables[0].Rows.RemoveAt(i);
                    //        i = i - 1;

                    //        break;
                    //    }
                    //}
                    //#endregion
                }
                //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                //{
                //    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                //    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                //    {
                //        if (ds.Tables[0].Rows[i]["F9"].ToString().Trim() == dgv_execl.Rows[a].Cells["MO"].Value.ToString().Trim())
                //        {
                //            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                //            dr["MO"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                //            dr["物料"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();                
                //            dr["status"] = "";
                //            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                //            ds.Tables[0].Rows.RemoveAt(i);
                //            i = i - 1;

                //            break;
                //        }
                //    }
                //    #endregion
                //}
                progressBar1.Visible = false;
                progressBar1.Value = 0;


                //根据DataGridView的列构造一个新的DataTable
                DataTable tb = new DataTable();
                foreach (DataGridViewColumn dgvc in dgv.Columns)
                {

                    if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                    {
                        DataColumn dc = new DataColumn();
                        dc.ColumnName = dgvc.DataPropertyName;
                        //dc.DataType = dgvc.ValueType;//若需要限制导入时的数据类型则取消注释，前提是DataGridView必须先绑定一个数据源那怕是空的DataTable
                        tb.Columns.Add(dc);
                    }
                }
                //根据Excel的行逐一对上面构造的DataTable的列进行赋值
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = tb.NewRow();
                    dr["consignor"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                    dr["so_no"] = "";
                    dr["so_day"] = str_time;
                    dr["customer_sale_no"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                    dr["customer_code"] = "";
                    dr["original_order_no"] = "";
                    dr["sku"] = ds.Tables[0].Rows[i]["sku"].ToString().Trim();
                    dr["pack_code"] = ds.Tables[0].Rows[i]["pack_code"].ToString().Trim();
                    dr["plan_so_qty_m"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                    dr["order_price"] = "0";
                    dr["order_unit"] = ds.Tables[0].Rows[i]["order_unit"].ToString().Trim();
                    dr["project_name"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();


                    dr["customer_name"] = "";
                    dr["receiver"] = "";
                    dr["CARRIER_PHONE"] = "";
                    dr["standby_12"] = "";
                    dr["telephone"] = "";
                    dr["need_time"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();
                    dr["address"] = "";
                    dr["rush_flag"] = "";
                    dr["carrier_address"] = "";
                    dr["standby_11"] = "";
                    dr["standby_13"] = "";
                    dr["standby_14"] = "";
                    dr["memo2"] = "";
                    if (ds.Tables[0].Rows[i]["F15"].ToString().Trim() == "'")
                    {
                        dr["memo"] = "";
                    }
                    else
                    {
                        dr["memo"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                    }

                    dr["standby_2"] = "";
                    dr["standby_3"] = "";
                    dr["lot_attribute9"] = "";
                    dr["lot_attribute6"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                    dr["lot_attribute11"] = "";
                    dr["lot_attribute10"] = "";
                    dr["lot_attribute15"] = "";
                    dr["lot_attribute12"] = "";

                    dr["lot_attribute1"] = "";
                    dr["lot_attribute2"] = "";
                    if (ds.Tables[0].Rows[i]["F13"].ToString().Trim() == "Y")
                    {
                        dr["lot_attribute3"] = "保税";
                    }
                    else if (ds.Tables[0].Rows[i]["F13"].ToString().Trim() == "y")
                    {
                        dr["lot_attribute3"] = "保税";
                    }
                    else
                    {
                        dr["lot_attribute3"] = "非保税";
                    }
                    dr["lot_attribute4"] = "";
                    dr["plan_cubage"] = "";
                    dr["plan_gross_weight"] = "";
                    dr["plan_net_weight"] = "";

                    dr["eas_no"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                    dr["line_type"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                    dr["mechine_no"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                    dr["mechine_type"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                    dr["sequence_no"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                    dr["work_position"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();

                    if (ds.Tables[0].Rows[i]["F2"].ToString().Trim() == "出库")
                    {
                        dr["so_type"] = "0";
                    }
                    else if (ds.Tables[0].Rows[i]["F2"].ToString().Trim() == "退货")
                    {
                        dr["so_type"] = "1";
                    }
                    else if (ds.Tables[0].Rows[i]["F2"].ToString().Trim() == "寄售")
                    {
                        dr["so_type"] = "2";
                    }
                    else if (ds.Tables[0].Rows[i]["F2"].ToString().Trim() == "移库")
                    {
                        dr["so_type"] = "3";
                    }
                    else if (ds.Tables[0].Rows[i]["F2"].ToString().Trim() == "销售")
                    {
                        dr["so_type"] = "4";
                    }
                    else if (ds.Tables[0].Rows[i]["F2"].ToString().Trim() == "寄存")
                    {
                        dr["so_type"] = "5";
                    }
                    else if (ds.Tables[0].Rows[i]["F2"].ToString().Trim() == "委外加工")
                    {
                        dr["so_type"] = "6";
                    }
                    else if (ds.Tables[0].Rows[i]["F2"].ToString().Trim() == "外协加工")
                    {
                        dr["so_type"] = "7";
                    }
                    else if (ds.Tables[0].Rows[i]["F2"].ToString().Trim() == "三包出库")
                    {
                        dr["so_type"] = "8";
                    }
                    else if (ds.Tables[0].Rows[i]["F2"].ToString().Trim() == "MO出库")
                    {
                        dr["so_type"] = "0";
                    }
                    else
                    {
                        dr["so_type"] = "0";
                    }
                    tb.Rows.Add(dr);
                }

                DataView DV = tb.DefaultView;
                DV.Sort = "customer_sale_no,need_time,work_position asc";
                tb = DV.ToTable();
                string str_so_no = "";
                if (tb.Rows.Count > 0)
                {
                    str_so_no = main.g_class.comm_getaccountno("so_no");
                    tb.Rows[0]["so_no"] = str_so_no;
                    if (tb.Rows.Count > 1)
                    {
                        for (int i = 0; i < tb.Rows.Count - 1; i++)
                        {
                            if (tb.Rows[i]["customer_sale_no"].ToString().Trim() == tb.Rows[i + 1]["customer_sale_no"].ToString().Trim()
                                && tb.Rows[i]["need_time"].ToString().Trim() == tb.Rows[i + 1]["need_time"].ToString().Trim()
                                && tb.Rows[i]["work_position"].ToString().Trim() == tb.Rows[i + 1]["work_position"].ToString().Trim())
                            {
                                tb.Rows[i + 1]["so_no"] = str_so_no;
                            }
                            else
                            {
                                str_so_no = main.g_class.comm_getaccountno("so_no");
                                tb.Rows[i + 1]["so_no"] = str_so_no;
                            }
                        }
                    }
                }

                //在DataGridView中显示导入的数据
                dgv.DataSource = tb;
                d_count = tb.Rows.Count;
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    dgv_execl.DataSource = null;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }

        public void EcxelToDataGridView_WXJS_CP(string filePath, DataGridView dgv)
        {
            //根据路径打开一个Excel文件并将数据填充到DataSet中
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            string str_file;

            str_file = cbx_file.Text.Trim();
            if (str_file.Substring(str_file.Length - 1) == "'")
            {
                str_file = str_file.Substring(0, str_file.Length - 1);
            }
            if (str_file.Substring(str_file.Length - 1) != "$")
            {
                str_file = str_file + "$";
            }
            if (str_file.Substring(0, 1) == "'")
            {
                str_file = str_file.Substring(1);
            }
            try
            {
                OleDbDataAdapter myCommand = null;
                DataSet ds = null;
                strExcel = "select  * from  [" + str_file + "]";
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["F1"].ToString().Trim() == "供应商代码" || ds.Tables[0].Rows[i]["F1"].ToString().Trim() == "工程项目")
                    {
                        ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                        i = i - 1;
                    }
                }
                d_sum = ds.Tables[0].Rows.Count;
                DataTable dt_execl = new DataTable();
                dt_execl.Columns.Add("status");
                dt_execl.Columns.Add("SAP SO");
                dt_execl.Columns.Add("物料");
                dt_execl.Columns.Add("旧物料编码");
                dt_execl.Columns.Add("机组序列号");
                dgv_execl.DataSource = dt_execl;
                DataSet ds_temp2;
                string str_sql2 = "";
                ds.Tables[0].Columns.Add("sku");
                ds.Tables[0].Columns.Add("pack_code");
                ds.Tables[0].Columns.Add("order_unit");
                progressBar1.Visible = true;
                progressBar1.Maximum = ds.Tables[0].Rows.Count;
                progressBar1.Value = 0;
                //DataSet ds_supply;
                //int i_count = 0;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    // i_count = 0;
                    progressBar1.Value = i;
                    #region SKU

                    str_sql2 = "  SELECT *from " + main.g_space + ".mst_sku where inv_org='" + main.g_org + "' and consignor='5061' and sku='" + ds.Tables[0].Rows[i]["F18"].ToString().Trim() + "'  and main_dist <> 'D'";
                    try
                    {
                        if (main.dbtype == "SQL")
                            ds_temp2 = main.dbservice.Sql_exec_selectsql(str_sql2);
                        else
                            ds_temp2 = main.dbservice.oracle_exec_selectsql(str_sql2);

                        if (ds_temp2.Tables[0].Rows.Count <= 0) //说明没有记录  
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();

                            dr["SAP SO"] = ds.Tables[0].Rows[i]["F21"].ToString().Trim();
                            dr["物料"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                            dr["旧物料编码"] = ds.Tables[0].Rows[i]["F20"].ToString().Trim();
                            dr["status"] = "缺档";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }
                        else
                        {
                            ds.Tables[0].Rows[i]["sku"] = ds_temp2.Tables[0].Rows[0]["sku"].ToString().Trim();
                            ds.Tables[0].Rows[i]["pack_code"] = ds_temp2.Tables[0].Rows[0]["pack_code"].ToString().Trim();
                            ds.Tables[0].Rows[i]["order_unit"] = ds_temp2.Tables[0].Rows[0]["main_unit"].ToString().Trim();

                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show("查找商品档案失败!" + ee.ToString());
                        return;
                    }

                    #endregion

                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {
                        if (ds.Tables[0].Rows[i]["F21"].ToString().Trim() == dgv_execl.Rows[a].Cells["SAP SO"].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["SAP SO"] = ds.Tables[0].Rows[i]["F21"].ToString().Trim();
                            dr["物料"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                            dr["旧物料编码"] = ds.Tables[0].Rows[i]["F20"].ToString().Trim();
                            dr["status"] = "";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;

                            break;
                        }
                    }
                    #endregion

                    #region 判断机组序列号
                    str_sql2 = "  select count(*) from " + main.g_space + ".so_ship_header a, " + main.g_space + ".so_ship_detail b " +
                               " where a.inv_org=b.inv_org and a.consignor=b.consignor and a.so_no=b.so_no and a.cross_flag='0' and b.sku='" + ds.Tables[0].Rows[i]["F18"].ToString().Trim() + "' and b.lot_attribute6='" + ds.Tables[0].Rows[i]["F22"].ToString().Trim() + "'";
                    try
                    {
                        int i_count = 0;
                        if (main.dbtype == "SQL")
                            i_count = main.dbservice.Sql_exec_selectint(str_sql2);
                        else
                            i_count = main.dbservice.oracle_exec_selectint(str_sql2);

                        if (i_count > 0) //说明没有记录  
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();

                            dr["SAP SO"] = ds.Tables[0].Rows[i]["F21"].ToString().Trim();
                            dr["物料"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                            dr["旧物料编码"] = ds.Tables[0].Rows[i]["F20"].ToString().Trim();
                            dr["机组序列号"] = ds.Tables[0].Rows[i]["F22"].ToString().Trim();
                            dr["status"] = " 机组序列号已经存在于出库单中";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;
                            continue;
                        }

                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show("查找出库单失败!" + ee.ToString());
                        return;
                    }
                    #endregion
                }
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    #region 判断如果有一个订单号中有一条数据没有档案，那整个单都不能导入
                    for (int a = 0; a < dgv_execl.Rows.Count; a++)
                    {
                        if (ds.Tables[0].Rows[i]["F21"].ToString().Trim() == dgv_execl.Rows[a].Cells["SAP SO"].Value.ToString().Trim())
                        {
                            DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                            dr["SAP SO"] = ds.Tables[0].Rows[i]["F21"].ToString().Trim();
                            dr["物料"] = ds.Tables[0].Rows[i]["F18"].ToString().Trim();
                            dr["旧物料编码"] = ds.Tables[0].Rows[i]["F20"].ToString().Trim();
                            dr["status"] = "";
                            ((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                            ds.Tables[0].Rows.RemoveAt(i);
                            i = i - 1;

                            break;
                        }
                    }
                    #endregion
                }
                progressBar1.Visible = false;
                progressBar1.Value = 0;


                //根据DataGridView的列构造一个新的DataTable
                DataTable tb = new DataTable();
                foreach (DataGridViewColumn dgvc in dgv.Columns)
                {

                    if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                    {
                        DataColumn dc = new DataColumn();
                        dc.ColumnName = dgvc.DataPropertyName;
                        //dc.DataType = dgvc.ValueType;//若需要限制导入时的数据类型则取消注释，前提是DataGridView必须先绑定一个数据源那怕是空的DataTable
                        tb.Columns.Add(dc);
                    }
                }

                //根据Excel的行逐一对上面构造的DataTable的列进行赋值

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = tb.NewRow();
                    dr["consignor"] = "5061";
                    dr["so_no"] = "";
                    dr["so_day"] = str_time;
                    dr["customer_sale_no"] = ds.Tables[0].Rows[i]["F21"].ToString().Trim();
                    dr["customer_code"] = ds.Tables[0].Rows[i]["F6"].ToString().Trim();
                    dr["original_order_no"] = "";
                    dr["sku"] = ds.Tables[0].Rows[i]["sku"].ToString().Trim();
                    dr["pack_code"] = ds.Tables[0].Rows[i]["pack_code"].ToString().Trim();
                    dr["plan_so_qty_m"] = ds.Tables[0].Rows[i]["F19"].ToString().Trim();
                    dr["order_price"] = ds.Tables[0].Rows[i]["F32"].ToString().Trim();
                    dr["order_unit"] = ds.Tables[0].Rows[i]["order_unit"].ToString().Trim();

                    // will1111

                    dr["project_name"] = ds.Tables[0].Rows[i]["F1"].ToString().Trim();


                    dr["customer_name"] = ds.Tables[0].Rows[i]["F2"].ToString().Trim();
                    dr["receiver"] = ds.Tables[0].Rows[i]["F3"].ToString().Trim();
                    dr["CARRIER_PHONE"] = ds.Tables[0].Rows[i]["F4"].ToString().Trim();
                    dr["standby_12"] = ds.Tables[0].Rows[i]["F5"].ToString().Trim();
                    dr["telephone"] = ds.Tables[0].Rows[i]["F7"].ToString().Trim();
                    dr["need_time"] = ds.Tables[0].Rows[i]["F8"].ToString().Trim();
                    dr["address"] = ds.Tables[0].Rows[i]["F9"].ToString().Trim();
                    dr["rush_flag"] = ds.Tables[0].Rows[i]["F10"].ToString().Trim();
                    dr["carrier_address"] = ds.Tables[0].Rows[i]["F11"].ToString().Trim();
                    dr["standby_11"] = ds.Tables[0].Rows[i]["F12"].ToString().Trim();
                    dr["standby_13"] = ds.Tables[0].Rows[i]["F13"].ToString().Trim();
                    dr["standby_14"] = ds.Tables[0].Rows[i]["F14"].ToString().Trim();
                    dr["memo2"] = ds.Tables[0].Rows[i]["F15"].ToString().Trim();
                    dr["memo"] = ds.Tables[0].Rows[i]["F27"].ToString().Trim();

                    dr["standby_2"] = ds.Tables[0].Rows[i]["F16"].ToString().Trim();
                    dr["standby_3"] = ds.Tables[0].Rows[i]["F17"].ToString().Trim();
                    dr["lot_attribute9"] = ds.Tables[0].Rows[i]["F21"].ToString().Trim();
                    dr["lot_attribute6"] = ds.Tables[0].Rows[i]["F22"].ToString().Trim();
                    dr["lot_attribute11"] = ds.Tables[0].Rows[i]["F23"].ToString().Trim();
                    dr["lot_attribute10"] = ds.Tables[0].Rows[i]["F24"].ToString().Trim();
                    dr["lot_attribute15"] = ds.Tables[0].Rows[i]["F25"].ToString().Trim();
                    if (ds.Tables[0].Rows[i]["F26"].ToString().Trim().Length > 10)//项目名称
                    {
                        dr["lot_attribute12"] = ds.Tables[0].Rows[i]["F26"].ToString().Trim().Substring(0, 10);
                    }
                    else
                    {
                        dr["lot_attribute12"] = ds.Tables[0].Rows[i]["F26"].ToString().Trim();
                    }
                    dr["lot_attribute1"] = ds.Tables[0].Rows[i]["F28"].ToString().Trim();
                    dr["lot_attribute2"] = ds.Tables[0].Rows[i]["F29"].ToString().Trim();
                    dr["lot_attribute3"] = ds.Tables[0].Rows[i]["F30"].ToString().Trim();
                    dr["lot_attribute4"] = ds.Tables[0].Rows[i]["F31"].ToString().Trim();
                    dr["plan_cubage"] = ds.Tables[0].Rows[i]["F33"].ToString().Trim();
                    dr["plan_gross_weight"] = ds.Tables[0].Rows[i]["F34"].ToString().Trim();
                    dr["plan_net_weight"] = ds.Tables[0].Rows[i]["F35"].ToString().Trim();

                    tb.Rows.Add(dr);
                }

                DataView DV = tb.DefaultView;
                DV.Sort = "customer_sale_no asc";
                tb = DV.ToTable();
                string str_so_no = "";
                if (tb.Rows.Count > 0)
                {
                    str_so_no = main.g_class.comm_getaccountno("so_no");
                    tb.Rows[0]["so_no"] = str_so_no;
                    if (tb.Rows.Count > 1)
                    {
                        for (int i = 0; i < tb.Rows.Count - 1; i++)
                        {
                            if (tb.Rows[i]["customer_sale_no"].ToString().Trim() == tb.Rows[i + 1]["customer_sale_no"].ToString().Trim())
                            {
                                tb.Rows[i + 1]["so_no"] = str_so_no;
                            }
                            else
                            {
                                str_so_no = main.g_class.comm_getaccountno("so_no");
                                tb.Rows[i + 1]["so_no"] = str_so_no;
                            }
                        }
                    }
                }

                //在DataGridView中显示导入的数据
                dgv.DataSource = tb;
                d_count = tb.Rows.Count;
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    dgv_execl.DataSource = null;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
        ///根据excel的文件的路径提取其中表的数据
        ///</summary>
        ///<paramname="Path">Excel文件的路径</param>
        private void GetDataFromExcelWithAppointSheetName(string Path)
        {
            //连接串
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + Path + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();

            //返回Excel的架构，包括各个sheet表的名称,类型，创建时间和修改时间等　
            DataTable dtSheetName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" });
            //包含excel中表名的字符串数组
            string[] strTableNames = new string[dtSheetName.Rows.Count];
            cbx_file.Items.Clear();
            cbx_file.ResetText();
            for (int k = 0; k < dtSheetName.Rows.Count; k++)
            {
                strTableNames[k] = dtSheetName.Rows[k]["TABLE_NAME"].ToString();
                cbx_file.Items.Add(strTableNames[k].Substring(0, strTableNames[k].Length - 1));
            }
            int i = dtSheetName.Rows.Count - 1;
            cbx_file.Text = strTableNames[i].Substring(0, strTableNames[i].Length - 1);
            //OleDbDataAdapter myCommand = null;
            //DataTable dt= new DataTable();
            //从指定的表明查询数据,可先把所有表明列出来供用户选择

            //string strExcel="select*from["+strTableNames[0]+"]";
            //myCommand = new OleDbDataAdapter(strExcel,strConn);
            //dt = new DataTable();
            //myCommand.Fill(dt);
            //dgv_asn.DataSource=dt;//绑定到界面
            if (cbx_file.Items.Count > 0)
            {
                cbx_file.SelectedIndex = 0;
            }
        }
        //保存
        private void btn_save_Click(object sender, EventArgs e)
        {
            decimal d_plan_so_qty_m, d_order_price;
            DataSet ds = new DataSet();
            string str_where, str_oldno = "", str_oldconsignor = "";
            Int32 li_count;
              
            if (dgv_asn.Rows.Count == 0) return;

            if (comboBox1.Text.Trim() == "标准模板")
            {
                #region 保存
                for (int i = 0; i < dgv_asn.Rows.Count; i++)
                {
                    string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();

                    string str_so_no = dgv_asn.Rows[i].Cells["so_no"].Value.ToString().Trim();

                    string str_so_day = dgv_asn.Rows[i].Cells["so_day"].Value.ToString().Trim();

                    string str_customer_sale_no = dgv_asn.Rows[i].Cells["customer_sale_no"].Value.ToString().Trim();

                    string str_customer_code = dgv_asn.Rows[i].Cells["customer_code"].Value.ToString().Trim();

                    string str_original_order_no = dgv_asn.Rows[i].Cells["original_order_no"].Value.ToString().Trim();

                    string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();

                    string str_pack_code = dgv_asn.Rows[i].Cells["pack_code"].Value.ToString().Trim();

                    if (dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim() == "")
                        d_plan_so_qty_m = 0;
                    else
                        d_plan_so_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);

                    if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                        d_order_price = 0;
                    else
                        d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);

                    string str_lot_attribute1 = dgv_asn.Rows[i].Cells["lot_attribute1"].Value.ToString().Trim();

                    string str_lot_attribute2 = dgv_asn.Rows[i].Cells["lot_attribute2"].Value.ToString().Trim();

                    string str_lot_attribute3 = dgv_asn.Rows[i].Cells["lot_attribute3"].Value.ToString().Trim();

                    string str_lot_attribute4 = dgv_asn.Rows[i].Cells["lot_attribute4"].Value.ToString().Trim();

                    string str_lot_attribute5 = dgv_asn.Rows[i].Cells["lot_attribute5"].Value.ToString().Trim();

                    string str_lot_attribute6 = dgv_asn.Rows[i].Cells["lot_attribute6"].Value.ToString().Trim();

                    string str_lot_attribute7 = dgv_asn.Rows[i].Cells["lot_attribute7"].Value.ToString().Trim();

                    string str_lot_attribute8 = dgv_asn.Rows[i].Cells["lot_attribute8"].Value.ToString().Trim();

                    string str_lot_attribute9 = dgv_asn.Rows[i].Cells["lot_attribute9"].Value.ToString().Trim();

                    string str_lot_attribute10 = dgv_asn.Rows[i].Cells["lot_attribute10"].Value.ToString().Trim();

                    string str_lot_attribute11 = dgv_asn.Rows[i].Cells["lot_attribute11"].Value.ToString().Trim();

                    string str_lot_attribute12 = dgv_asn.Rows[i].Cells["lot_attribute12"].Value.ToString().Trim();

                    string str_lot_attribute13 = dgv_asn.Rows[i].Cells["lot_attribute13"].Value.ToString().Trim();

                    string str_lot_attribute14 = dgv_asn.Rows[i].Cells["lot_attribute14"].Value.ToString().Trim();

                    string str_lot_attribute15 = dgv_asn.Rows[i].Cells["lot_attribute15"].Value.ToString().Trim();


                    //货主是否为空
                    if (str_consignor == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                        break;
                    }
                    //判断货主是否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_customer a where a.inv_org = '" + main.g_org + "' and a.consignor ='" + str_consignor + "' and   a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where  mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }

                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Consignor is not exists or haven't privilege", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是否为空
                    if (str_sku == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是 否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_sku  where inv_org = '" + main.g_org + "' and consignor ='" + str_consignor + "' and sku ='" + str_sku + "'";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }

                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("sku is not exists ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //出库单号是否为空
                    if (str_so_no == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a so no ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    //包装编码
                    if (str_pack_code == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a pack code ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    //订货主数量是否为空
                    if (d_plan_so_qty_m == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input plan_so_qty_m ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //订单日期
                    if (str_so_day == "")
                    {
                        str_so_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                    }

                    //判断表头是否存在
                    int count;
                    string str_temp1 = "select count(*) from " + main.g_space + ".so_ship_header where inv_org = '" + main.g_org + "' and consignor='" + str_consignor + "'and so_no='" + str_so_no + "'";
                    if (main.dbtype == "SQL")
                    {
                        count = main.dbservice.Sql_exec_selectint(str_temp1);
                    }
                    else
                    {
                        count = main.dbservice.oracle_exec_selectint(str_temp1);
                    }

                    if (count > 0)
                    {
                        //MessageBox.Show(main.g_class.comm_getchangestring("asn no have exists ", main.g_info_dataset) + "!" + str_consignor + "/" + str_asn_no);
                        //dgv_asn.Rows.Remove(dgv_asn.Rows[dgv_asn.Rows[i].Index]);
                        continue;
                    }
                    else
                    {
                        int k = 0;
                        ds_update.Tables[0].Clear();
                        for (int n = 0; n < dgv_asn.Rows.Count; n++)
                        {
                            str_oldno = dgv_asn.Rows[n].Cells["so_no"].Value.ToString().Trim();
                            str_oldconsignor = dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                            if (str_oldno == str_so_no && str_oldconsignor == str_consignor)
                            {
                                DataRow dgrow;
                                k = k + 1;
                                dgrow = ds_update.Tables[0].NewRow();
                                dgrow["inv_org"] = main.g_org;
                                dgrow["consignor"] = (string)dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                                dgrow["so_no"] = (string)dgv_asn.Rows[n].Cells["so_no"].Value.ToString().Trim();
                                dgrow["so_line_no"] = k;
                                dgrow["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                dgrow["pack_code"] = (string)dgv_asn.Rows[n].Cells["pack_code"].Value.ToString().Trim();
                                dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                dgrow["order_price"] = (string)dgv_asn.Rows[n].Cells["order_price"].Value.ToString().Trim();
                                dgrow["lot_attribute1"] = (string)dgv_asn.Rows[n].Cells["lot_attribute1"].Value.ToString().Trim();
                                dgrow["lot_attribute2"] = (string)dgv_asn.Rows[n].Cells["lot_attribute2"].Value.ToString().Trim();
                                dgrow["lot_attribute3"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                dgrow["lot_attribute4"] = (string)dgv_asn.Rows[n].Cells["lot_attribute4"].Value.ToString().Trim();
                                dgrow["lot_attribute5"] = (string)dgv_asn.Rows[n].Cells["lot_attribute5"].Value.ToString().Trim();
                                dgrow["lot_attribute6"] = (string)dgv_asn.Rows[n].Cells["lot_attribute6"].Value.ToString().Trim();
                                dgrow["lot_attribute7"] = (string)dgv_asn.Rows[n].Cells["lot_attribute7"].Value.ToString().Trim();
                                dgrow["lot_attribute8"] = (string)dgv_asn.Rows[n].Cells["lot_attribute8"].Value.ToString().Trim();
                                dgrow["lot_attribute9"] = (string)dgv_asn.Rows[n].Cells["lot_attribute9"].Value.ToString().Trim();
                                dgrow["lot_attribute10"] = (string)dgv_asn.Rows[n].Cells["lot_attribute10"].Value.ToString().Trim();
                                dgrow["lot_attribute11"] = (string)dgv_asn.Rows[n].Cells["lot_attribute11"].Value.ToString().Trim();
                                dgrow["lot_attribute12"] = (string)dgv_asn.Rows[n].Cells["lot_attribute12"].Value.ToString().Trim();
                                dgrow["lot_attribute13"] = (string)dgv_asn.Rows[n].Cells["lot_attribute13"].Value.ToString().Trim();
                                dgrow["lot_attribute14"] = (string)dgv_asn.Rows[n].Cells["lot_attribute14"].Value.ToString().Trim();
                                dgrow["lot_attribute15"] = (string)dgv_asn.Rows[n].Cells["lot_attribute15"].Value.ToString().Trim();
                                dgrow["main_dist"] = "A";
                                dgrow["made_time"] = (string)DateTime.Now.ToString("yyyy.MM.dd").Trim();
                                dgrow["maker"] = main.g_user;
                                ds_update.Tables[0].Rows.Add(dgrow);
                            }
                        }

                        string str_insert;
                        if (main.dbtype == "SQL")
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                        " so_flag,so_status,ext_dist,main_dist,made_time,maker )  " +
                                                            " values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                    "'" + str_customer_code + "','" + str_original_order_no + "','0','0','0','0','A', getdate(),'" + main.g_user + "')";
                        }
                        else
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                         " so_flag,so_status,ext_dist,main_dist,made_time,maker )  " +
                                                             "  values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                      "'" + str_customer_code + "','" + str_original_order_no + "','0','0','0','0','A', sysdate,'" + main.g_user + "')";
                        }
                        try
                        {
                            if (main.dbtype == "SQL")
                                main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                            else
                                main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);
                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }
                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                MessageBox.Show(main.g_class.comm_getchangestring("Success to save ", main.g_info_dataset) + "!");
                #endregion
            }
            else if (main.g_class.comm_getconversestring(comboBox1.Text.Trim(), main.g_info_dataset).ToLower() == "control products")
            {
                #region 保存 江森模板1
                string str_sql;
                DataSet ds_temp;
                decimal d_convert = 0, d_cubage = 0, d_gross_weight = 0, d_net_weight = 0;
                string str_main_unit = "", str_sub_unit = "";
                DataSet ds_customer;
                progressBar1.Visible = true;
                string str_consignor_name = "", str_telephone = "", str_clerk = "";
                progressBar1.Maximum = dgv_asn.Rows.Count;
                progressBar1.Value = 0;
                for (int i = 0; i < dgv_asn.Rows.Count; i++)
                {
                    progressBar1.Value = i;

                    string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();

                    string str_so_no = dgv_asn.Rows[i].Cells["so_no"].Value.ToString().Trim();
                    string str_address = dgv_asn.Rows[i].Cells["address"].Value.ToString().Trim();
                    string str_so_day = dgv_asn.Rows[i].Cells["so_day"].Value.ToString().Trim();

                    string str_customer_sale_no = dgv_asn.Rows[i].Cells["customer_sale_no"].Value.ToString().Trim();
                    string str_order_unit = dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();
                    string str_customer_code = dgv_asn.Rows[i].Cells["customer_code"].Value.ToString().Trim();

                    string str_original_order_no = dgv_asn.Rows[i].Cells["original_order_no"].Value.ToString().Trim();

                    string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();

                    string str_pack_code = dgv_asn.Rows[i].Cells["pack_code"].Value.ToString().Trim();
                    string str_project_name = dgv_asn.Rows[i].Cells["project_name"].Value.ToString().Trim();
                    if (dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim() == "")
                        d_plan_so_qty_m = 0;
                    else
                        d_plan_so_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);

                    if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                        d_order_price = 0;
                    else
                        d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);

                    string str_lot_attribute1 = dgv_asn.Rows[i].Cells["lot_attribute1"].Value.ToString().Trim();

                    string str_lot_attribute2 = dgv_asn.Rows[i].Cells["lot_attribute2"].Value.ToString().Trim();

                    string str_lot_attribute3 = dgv_asn.Rows[i].Cells["lot_attribute3"].Value.ToString().Trim();

                    string str_lot_attribute4 = dgv_asn.Rows[i].Cells["lot_attribute4"].Value.ToString().Trim();

                    string str_lot_attribute5 = dgv_asn.Rows[i].Cells["lot_attribute5"].Value.ToString().Trim();

                    string str_lot_attribute6 = dgv_asn.Rows[i].Cells["lot_attribute6"].Value.ToString().Trim();

                    string str_lot_attribute7 = dgv_asn.Rows[i].Cells["lot_attribute7"].Value.ToString().Trim();

                    string str_lot_attribute8 = dgv_asn.Rows[i].Cells["lot_attribute8"].Value.ToString().Trim();

                    string str_lot_attribute9 = dgv_asn.Rows[i].Cells["lot_attribute9"].Value.ToString().Trim();

                    string str_lot_attribute10 = dgv_asn.Rows[i].Cells["lot_attribute10"].Value.ToString().Trim();

                    string str_lot_attribute11 = dgv_asn.Rows[i].Cells["lot_attribute11"].Value.ToString().Trim();

                    string str_lot_attribute12 = dgv_asn.Rows[i].Cells["lot_attribute12"].Value.ToString().Trim();

                    string str_lot_attribute13 = dgv_asn.Rows[i].Cells["lot_attribute13"].Value.ToString().Trim();

                    string str_lot_attribute14 = dgv_asn.Rows[i].Cells["lot_attribute14"].Value.ToString().Trim();

                    string str_lot_attribute15 = dgv_asn.Rows[i].Cells["lot_attribute15"].Value.ToString().Trim();
                    string str_rush_flag = "";
                    if (dgv_asn.Rows[i].Cells["rush_flag"].Value != null)
                    {
                        if (dgv_asn.Rows[i].Cells["rush_flag"].Value.ToString().Trim() != "")
                        {
                            str_rush_flag = "1";
                        }
                        else
                        {
                            str_rush_flag = "0";
                        }
                    }
                    else
                    {
                        str_rush_flag = "0";
                    }
                    string str_standby_11 = dgv_asn.Rows[i].Cells["standby_11"].Value.ToString().Trim();
                    string str_standby_12 = dgv_asn.Rows[i].Cells["standby_12"].Value.ToString().Trim();
                    string str_standby_13 = dgv_asn.Rows[i].Cells["standby_13"].Value.ToString().Trim();

                    //货主是否为空
                    if (str_consignor == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                        break;
                    }
                    //判断货主是否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_customer a where a.inv_org = '" + main.g_org + "' and a.consignor ='" + str_consignor + "' and   a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where  mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }

                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Consignor is not exists or haven't privilege", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是否为空
                    if (str_sku == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    //出库单号是否为空
                    if (str_customer_sale_no == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a customer_sale_no ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }



                    //订货主数量是否为空
                    if (d_plan_so_qty_m == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input plan_so_qty_m ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //订单日期
                    if (str_so_day == "")
                    {
                        str_so_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                    }

                    //判断表头是否存在
                    int count;
                    string str_temp1 = "select count(*) from " + main.g_space + ".so_ship_header where inv_org = '" + main.g_org + "' and consignor='" + str_consignor + "'and so_no='" + str_so_no + "' ";
                    if (main.dbtype == "SQL")
                    {
                        count = main.dbservice.Sql_exec_selectint(str_temp1);
                    }
                    else
                    {
                        count = main.dbservice.oracle_exec_selectint(str_temp1);
                    }

                    if (count > 0)
                    {
                        //MessageBox.Show(main.g_class.comm_getchangestring("asn no have exists ", main.g_info_dataset) + "!" + str_consignor + "/" + str_asn_no);
                        //dgv_asn.Rows.Remove(dgv_asn.Rows[dgv_asn.Rows[i].Index]);
                        continue;
                    }
                    else
                    {

                        if (str_customer_code.Trim() != "")
                        {
                            str_sql = "select consignor_name,business_address,telephone,clerk from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and consignor = '" + str_customer_code.Trim() + "'";
                            if (main.dbtype == "SQL")
                            {
                                ds_customer = main.dbservice.Sql_exec_selectsql(str_sql);
                            }
                            else
                            {
                                ds_customer = main.dbservice.oracle_exec_selectsql(str_sql);
                            }
                            if (ds_customer.Tables[0].Rows.Count > 0) //说明有数据
                            {
                                str_consignor_name = ds_customer.Tables[0].Rows[0]["consignor_name"].ToString().Trim();
                                str_telephone = ds_customer.Tables[0].Rows[0]["telephone"].ToString().Trim();
                                str_clerk = ds_customer.Tables[0].Rows[0]["clerk"].ToString().Trim();
                                if (str_address.Trim() == "")
                                {
                                    str_address = ds_customer.Tables[0].Rows[0]["business_address"].ToString().Trim();
                                }
                            }
                            else
                            {
                                str_consignor_name = "";
                                str_telephone = "";
                                str_clerk = "";
                            }
                        }
                        //str_so_no = main.g_class.comm_getaccountno("so_no");
                        string str_insert;
                        if (main.dbtype == "SQL")
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                        " so_flag,so_status,main_dist,made_time,maker,rush_flag,cross_flag,so_prior,wave_flag,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12,standby_13,project_name)  " +
                                                            " values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                    "'" + str_customer_code + "','" + str_original_order_no + "','0','0','0','A', getdate(),'" + main.g_user + "','" + str_rush_flag + "','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_clerk + "','" + str_consignor_name + "','" + str_standby_11 + "','" + str_standby_12 + "','" + str_standby_13 + "','" + str_project_name + "')";
                        }
                        else
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                         " so_flag,so_status,main_dist,made_time,maker,,rush_flag,cross_flag,so_prior,wave_flag ,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12,standby_13,project_name)  " +
                                                             "  values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                      "'" + str_customer_code + "','" + str_original_order_no + "','0','0','0','A', sysdate,'" + main.g_user + "','" + str_rush_flag + "','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_clerk + "','" + str_consignor_name + "','" + str_standby_11 + "','" + str_standby_12 + "','" + str_standby_13 + "','" + str_project_name + "')";
                        }

                        int k = 0;
                        ds_update.Tables[0].Clear();
                        bool b_temp = false;
                        for (int n = 0; n < dgv_asn.Rows.Count; n++)
                        {
                            str_oldno = dgv_asn.Rows[n].Cells["so_no"].Value.ToString().Trim();
                            str_oldconsignor = dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();

                            if (str_oldno == str_so_no && str_oldconsignor == str_consignor)
                            {
                                DataRow dgrow;
                                k = k + 1;
                                dgrow = ds_update.Tables[0].NewRow();
                                dgrow["inv_org"] = main.g_org;
                                dgrow["consignor"] = (string)dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                                dgrow["so_no"] = str_so_no;
                                dgrow["so_line_no"] = k;
                                dgrow["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                //根据SKU找出包装和单位
                                //DataSet ds_temp2;
                                //string str_sql2;

                                dgrow["pack_code"] = (string)dgv_asn.Rows[n].Cells["pack_code"].Value.ToString().Trim();
                                str_order_unit = (string)dgv_asn.Rows[n].Cells["order_unit"].Value.ToString().Trim();
                                dgrow["order_price"] = (string)dgv_asn.Rows[n].Cells["order_price"].Value.ToString().Trim();
                                dgrow["lot_attribute1"] = (string)dgv_asn.Rows[n].Cells["lot_attribute1"].Value.ToString().Trim();
                                dgrow["lot_attribute2"] = (string)dgv_asn.Rows[n].Cells["lot_attribute2"].Value.ToString().Trim();
                                dgrow["lot_attribute3"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                dgrow["lot_attribute4"] = (string)dgv_asn.Rows[n].Cells["lot_attribute4"].Value.ToString().Trim();
                                dgrow["lot_attribute5"] = (string)dgv_asn.Rows[n].Cells["lot_attribute5"].Value.ToString().Trim();
                                dgrow["lot_attribute6"] = (string)dgv_asn.Rows[n].Cells["lot_attribute6"].Value.ToString().Trim();
                                dgrow["lot_attribute7"] = (string)dgv_asn.Rows[n].Cells["lot_attribute7"].Value.ToString().Trim();
                                dgrow["lot_attribute8"] = (string)dgv_asn.Rows[n].Cells["lot_attribute8"].Value.ToString().Trim();
                                dgrow["lot_attribute9"] = (string)dgv_asn.Rows[n].Cells["lot_attribute9"].Value.ToString().Trim();
                                dgrow["lot_attribute10"] = (string)dgv_asn.Rows[n].Cells["lot_attribute10"].Value.ToString().Trim();
                                dgrow["lot_attribute11"] = (string)dgv_asn.Rows[n].Cells["lot_attribute11"].Value.ToString().Trim();
                                dgrow["lot_attribute12"] = (string)dgv_asn.Rows[n].Cells["lot_attribute12"].Value.ToString().Trim();
                                dgrow["lot_attribute13"] = (string)dgv_asn.Rows[n].Cells["lot_attribute13"].Value.ToString().Trim();
                                dgrow["lot_attribute14"] = (string)dgv_asn.Rows[n].Cells["lot_attribute14"].Value.ToString().Trim();
                                dgrow["lot_attribute15"] = (string)dgv_asn.Rows[n].Cells["lot_attribute15"].Value.ToString().Trim();
                                dgrow["standby_3"] = (string)dgv_asn.Rows[n].Cells["standby_3"].Value.ToString().Trim();
                                dgrow["main_dist"] = "A";
                                dgrow["made_time"] = (string)DateTime.Now.ToString("yyyy.MM.dd").Trim();
                                dgrow["maker"] = main.g_user;


                                dgrow["standby_6"] = 0;
                                dgrow["standby_7"] = 0;
                                dgrow["so_status"] = "0";

                                dgrow["ship_qty_m"] = 0;
                                dgrow["ship_qty_s"] = 0;
                                str_sql = "  SELECT *from WMS.mst_sku where inv_org='" + main.g_org + "' and consignor='" + dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim() + "' and sku='" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim() + "' and  main_dist <> 'D'";
                                try
                                {
                                    if (main.dbtype == "SQL")
                                        ds_temp = main.dbservice.Sql_exec_selectsql(str_sql);
                                    else
                                        ds_temp = main.dbservice.oracle_exec_selectsql(str_sql);

                                    if (ds_temp.Tables[0].Rows.Count > 0) //说明有记录，默认第一条  
                                    {
                                        str_main_unit = "";
                                        str_sub_unit = "";
                                        str_main_unit = ds_temp.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                                        str_sub_unit = ds_temp.Tables[0].Rows[0]["sub_unit"].ToString().Trim();
                                        d_convert = 0; d_cubage = 0; d_gross_weight = 0; d_net_weight = 0;
                                        d_convert = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["convert_modulus"].ToString().Trim());
                                        if (ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim() != "")
                                        {
                                            d_cubage = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_cubage = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim() != "")
                                        {
                                            d_gross_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_gross_weight = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim() != "")
                                        {
                                            d_net_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_net_weight = 0;
                                        }
                                        if (str_main_unit.Trim() == str_order_unit)//单位是主数量
                                        {
                                            dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else if (str_sub_unit.Trim() == str_order_unit)//辅数量
                                        {
                                            dgrow["plan_so_qty_s"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_m"] = Math.Round(Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()) / d_convert, 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else
                                        {
                                            dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        dgrow["convert_modulus"] = d_convert.ToString();

                                        dgrow["main_sub_flag"] = ds_temp.Tables[0].Rows[0]["main_sub_flag"].ToString().Trim();

                                        dgrow["plan_cubage"] = Math.Round(d_cubage * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["plan_gross_weight"] = Math.Round(d_gross_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["plan_net_weight"] = Math.Round(d_net_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                    }
                                    else
                                    {
                                        //DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                                        //dr["customer_order_no"] = (string)dgv_asn.Rows[n].Cells["original_order_no"].Value.ToString().Trim();
                                        //dr["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                        //((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                        //b_temp = true;
                                    }
                                }
                                catch (System.Exception ee)
                                {
                                    MessageBox.Show("查找商品档案失败!" + ee.ToString());
                                    return;
                                }
                                ds_update.Tables[0].Rows.Add(dgrow);
                            }
                        }
                        //如果有找不到档案的就存到临时表 
                        if (b_temp) continue;
                        try
                        {
                            if (main.dbtype == "SQL")
                                main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                            else
                                main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);


                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }
                progressBar1.Visible = false;
                progressBar1.Value = 0;

                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                MessageBox.Show(main.g_class.comm_getchangestring("导入成功,EXECL中有" + d_sum.ToString() + "行，导入成功" + d_count.ToString() + "行，失败" + Convert.ToString(d_sum - d_count) + "行。", main.g_info_dataset) + "!");
                #endregion
            }
            else if (main.g_class.comm_getconversestring(comboBox1.Text.Trim(), main.g_info_dataset).ToLower() == "service parts")
            {
                #region 保存 江森模板2
                string str_sql;
                DataSet ds_temp;
                decimal d_convert = 0, d_cubage = 0, d_gross_weight = 0, d_net_weight = 0;
                string str_main_unit = "";
                string str_sub_unit = "";
                DataSet ds_customer;

                string str_consignor_name = "", str_telephone = "", str_clerk = "";
                progressBar1.Visible = true;
                progressBar1.Maximum = dgv_asn.Rows.Count;
                progressBar1.Value = 0;
                for (int i = 0; i < dgv_asn.Rows.Count; i++)
                {
                    //如果临时表中有数据，就判断一下如果存在于临时表中的订单号就不能导入
                    bool b_temp2 = false;
                    if (dgv_execl.Rows.Count > 0)
                    {
                        for (int c = 0; c < dgv_execl.Rows.Count; c++)
                        {
                            if (dgv_asn.Rows[i].Cells["original_order_no"].Value.ToString().Trim() == dgv_execl.Rows[c].Cells["customer_order_no2"].Value.ToString().Trim())
                            {
                                b_temp2 = true;
                                break;
                            }
                        }
                    }
                    //如果已经存在临时表中，跳过这就条
                    if (b_temp2) continue;

                    string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();

                    string str_so_no = dgv_asn.Rows[i].Cells["so_no"].Value.ToString().Trim();

                    string str_so_day = dgv_asn.Rows[i].Cells["so_day"].Value.ToString().Trim();

                    string str_customer_sale_no = dgv_asn.Rows[i].Cells["customer_sale_no"].Value.ToString().Trim();

                    string str_customer_code = dgv_asn.Rows[i].Cells["customer_code"].Value.ToString().Trim();

                    string str_original_order_no = dgv_asn.Rows[i].Cells["original_order_no"].Value.ToString().Trim();

                    string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();

                    string str_pack_code = dgv_asn.Rows[i].Cells["pack_code"].Value.ToString().Trim();

                    if (dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim() == "")
                        d_plan_so_qty_m = 0;
                    else
                        d_plan_so_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);

                    if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                        d_order_price = 0;
                    else
                        d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);

                    string str_address = dgv_asn.Rows[i].Cells["address"].Value.ToString().Trim();
                    string str_lot_attribute1 = dgv_asn.Rows[i].Cells["lot_attribute1"].Value.ToString().Trim();

                    string str_lot_attribute2 = dgv_asn.Rows[i].Cells["lot_attribute2"].Value.ToString().Trim();

                    string str_lot_attribute3 = dgv_asn.Rows[i].Cells["lot_attribute3"].Value.ToString().Trim();

                    string str_lot_attribute4 = dgv_asn.Rows[i].Cells["lot_attribute4"].Value.ToString().Trim();

                    string str_lot_attribute5 = dgv_asn.Rows[i].Cells["lot_attribute5"].Value.ToString().Trim();

                    string str_lot_attribute6 = dgv_asn.Rows[i].Cells["lot_attribute6"].Value.ToString().Trim();

                    string str_lot_attribute7 = dgv_asn.Rows[i].Cells["lot_attribute7"].Value.ToString().Trim();

                    string str_lot_attribute8 = dgv_asn.Rows[i].Cells["lot_attribute8"].Value.ToString().Trim();

                    string str_lot_attribute9 = dgv_asn.Rows[i].Cells["lot_attribute9"].Value.ToString().Trim();

                    string str_lot_attribute10 = dgv_asn.Rows[i].Cells["lot_attribute10"].Value.ToString().Trim();

                    string str_lot_attribute11 = dgv_asn.Rows[i].Cells["lot_attribute11"].Value.ToString().Trim();

                    string str_lot_attribute12 = dgv_asn.Rows[i].Cells["lot_attribute12"].Value.ToString().Trim();

                    string str_lot_attribute13 = dgv_asn.Rows[i].Cells["lot_attribute13"].Value.ToString().Trim();

                    string str_lot_attribute14 = dgv_asn.Rows[i].Cells["lot_attribute14"].Value.ToString().Trim();

                    string str_lot_attribute15 = dgv_asn.Rows[i].Cells["lot_attribute15"].Value.ToString().Trim();
                    string str_order_unit = dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();
                    string str_standby_11 = dgv_asn.Rows[i].Cells["standby_11"].Value.ToString().Trim();
                    string str_standby_12 = dgv_asn.Rows[i].Cells["standby_12"].Value.ToString().Trim();
                    string str_standby_13 = dgv_asn.Rows[i].Cells["standby_13"].Value.ToString().Trim();
                    string str_rush_flag = "";
                    if (dgv_asn.Rows[i].Cells["rush_flag"].Value != null)
                    {
                        if (dgv_asn.Rows[i].Cells["rush_flag"].Value.ToString().Trim() != "")
                        {
                            str_rush_flag = "1";
                        }
                        else
                        {
                            str_rush_flag = "0";
                        }
                    }
                    else
                    {
                        str_rush_flag = "0";
                    }
                    //货主是否为空
                    if (str_consignor == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                        break;
                    }
                    //判断货主是否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_customer a where a.inv_org = '" + main.g_org + "' and a.consignor ='" + str_consignor + "' and   a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where  mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }

                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Consignor is not exists or haven't privilege", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是否为空
                    if (str_sku == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    //出库单号是否为空
                    ////////if (str_customer_sale_no == "")
                    ////////{
                    ////////    MessageBox.Show(main.g_class.comm_getchangestring("Please input a customer_sale_no ", main.g_info_dataset) + "!");
                    ////////    dgv_asn.Rows[i].Selected = true;
                    ////////    break;
                    ////////}

                    ////包装编码
                    //if (str_pack_code == "")
                    //{
                    //    MessageBox.Show(main.g_class.comm_getchangestring("Please input a pack code ", main.g_info_dataset) + "!");
                    //    dgv_asn.Rows[i].Selected = true;
                    //    break;
                    //}

                    //订货主数量是否为空
                    if (d_plan_so_qty_m == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input plan_so_qty_m ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    ////订单日期
                    //if (str_so_day == "")
                    //{
                    //    str_so_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                    //}

                    //判断表头是否存在
                    int count;
                    string str_temp1 = "select count(*) from " + main.g_space + ".so_ship_header where inv_org = '" + main.g_org + "' and consignor='" + str_consignor + "'and so_no='" + str_so_no + "'";
                    if (main.dbtype == "SQL")
                    {
                        count = main.dbservice.Sql_exec_selectint(str_temp1);
                    }
                    else
                    {
                        count = main.dbservice.oracle_exec_selectint(str_temp1);
                    }

                    if (count > 0)
                    {
                        //MessageBox.Show(main.g_class.comm_getchangestring("asn no have exists ", main.g_info_dataset) + "!" + str_consignor + "/" + str_asn_no);
                        //dgv_asn.Rows.Remove(dgv_asn.Rows[dgv_asn.Rows[i].Index]);
                        continue;
                    }
                    else
                    {
                        //str_so_no = main.g_class.comm_getaccountno("so_no");
                        //if (str_address.Trim() == "")
                        //{
                        if (str_customer_code.Trim() != "")
                        {
                            str_sql = "select consignor_name,business_address,telephone,clerk from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and consignor = '" + str_customer_code.Trim() + "'";
                            if (main.dbtype == "SQL")
                            {
                                ds_customer = main.dbservice.Sql_exec_selectsql(str_sql);
                            }
                            else
                            {
                                ds_customer = main.dbservice.oracle_exec_selectsql(str_sql);
                            }
                            if (ds_customer.Tables[0].Rows.Count > 0) //说明有数据
                            {
                                str_consignor_name = ds_customer.Tables[0].Rows[0]["consignor_name"].ToString().Trim();
                                str_telephone = "";
                                str_clerk = "";

                                //str_telephone = ds_customer.Tables[0].Rows[0]["telephone"].ToString().Trim();
                                //str_clerk = ds_customer.Tables[0].Rows[0]["clerk"].ToString().Trim();
                                //if (str_telephone.Length > 20)
                                //{
                                //    str_telephone = str_telephone.Substring(0, 19);
                                //}
                                //if (str_address.Trim() == "")
                                //{
                                //    str_address = ds_customer.Tables[0].Rows[0]["business_address"].ToString().Trim();
                                //}
                            }
                            else
                            {
                                str_consignor_name = "";
                                str_telephone = "";
                                str_clerk = "";
                            }
                        }
                        //}
                        string str_insert;
                        if (main.dbtype == "SQL")
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                        " so_flag,so_status,main_dist,made_time,maker,rush_flag,cross_flag,so_prior,wave_flag,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12,standby_13)  " +
                                                            " values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                    "'" + str_customer_code + "','" + str_original_order_no + "','4','0','0','A', getdate(),'" + main.g_user + "','" + str_rush_flag + "','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_clerk + "','" + str_consignor_name + "','" + str_standby_11.Trim() + "','" + str_standby_12.Trim() + "','" + str_standby_13.Trim() + "')";
                        }
                        else
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                         " so_flag,so_status,main_dist,made_time,maker,,rush_flag,cross_flag,so_prior,wave_flag ,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12,standby_13)  " +
                                                             "  values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                      "'" + str_customer_code + "','" + str_original_order_no + "','4','0','0','A', sysdate,'" + main.g_user + "','" + str_rush_flag + "','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_clerk + "','" + str_consignor_name + "','" + str_standby_11.Trim() + "','" + str_standby_12.Trim() + "','" + str_standby_13.Trim() + "')";
                        }

                        int k = 0;
                        ds_update.Tables[0].Clear();
                        //bool b_temp = false;
                        for (int n = 0; n < dgv_asn.Rows.Count; n++)
                        {
                            str_oldno = dgv_asn.Rows[n].Cells["so_no"].Value.ToString().Trim();
                            str_oldconsignor = dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                            if (str_oldno == str_so_no && str_oldconsignor == str_consignor)
                            {
                                DataRow dgrow;
                                k = k + 1;
                                dgrow = ds_update.Tables[0].NewRow();
                                dgrow["inv_org"] = main.g_org;
                                dgrow["consignor"] = (string)dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                                dgrow["so_no"] = str_so_no;
                                dgrow["so_line_no"] = k;
                                dgrow["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                //根据SKU找出包装和单位
                                //DataSet ds_temp2;
                                //string str_sql2;

                                dgrow["pack_code"] = (string)dgv_asn.Rows[n].Cells["pack_code"].Value.ToString().Trim();

                                str_order_unit = (string)dgv_asn.Rows[n].Cells["order_unit"].Value.ToString().Trim();
                                //dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                dgrow["order_price"] = (string)dgv_asn.Rows[n].Cells["order_price"].Value.ToString().Trim();
                                dgrow["lot_attribute1"] = (string)dgv_asn.Rows[n].Cells["lot_attribute1"].Value.ToString().Trim();
                                dgrow["lot_attribute2"] = (string)dgv_asn.Rows[n].Cells["lot_attribute2"].Value.ToString().Trim();
                                dgrow["lot_attribute3"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                dgrow["lot_attribute4"] = (string)dgv_asn.Rows[n].Cells["lot_attribute4"].Value.ToString().Trim();
                                dgrow["lot_attribute5"] = (string)dgv_asn.Rows[n].Cells["lot_attribute5"].Value.ToString().Trim();
                                dgrow["lot_attribute6"] = (string)dgv_asn.Rows[n].Cells["lot_attribute6"].Value.ToString().Trim();
                                dgrow["lot_attribute7"] = (string)dgv_asn.Rows[n].Cells["lot_attribute7"].Value.ToString().Trim();
                                dgrow["lot_attribute8"] = (string)dgv_asn.Rows[n].Cells["lot_attribute8"].Value.ToString().Trim();
                                dgrow["lot_attribute9"] = (string)dgv_asn.Rows[n].Cells["lot_attribute9"].Value.ToString().Trim();
                                dgrow["lot_attribute10"] = (string)dgv_asn.Rows[n].Cells["lot_attribute10"].Value.ToString().Trim();
                                dgrow["lot_attribute11"] = (string)dgv_asn.Rows[n].Cells["lot_attribute11"].Value.ToString().Trim();
                                dgrow["lot_attribute12"] = (string)dgv_asn.Rows[n].Cells["lot_attribute12"].Value.ToString().Trim();
                                dgrow["lot_attribute13"] = (string)dgv_asn.Rows[n].Cells["lot_attribute13"].Value.ToString().Trim();
                                dgrow["lot_attribute14"] = (string)dgv_asn.Rows[n].Cells["lot_attribute14"].Value.ToString().Trim();
                                dgrow["lot_attribute15"] = (string)dgv_asn.Rows[n].Cells["lot_attribute15"].Value.ToString().Trim();
                                dgrow["main_dist"] = "A";
                                dgrow["made_time"] = (string)DateTime.Now.ToString("yyyy.MM.dd").Trim();
                                dgrow["maker"] = main.g_user;

                                dgrow["ship_qty_m"] = 0;
                                dgrow["ship_qty_s"] = 0;
                                dgrow["standby_6"] = 0;
                                dgrow["standby_7"] = 0;
                                dgrow["standby_2"] = (string)dgv_asn.Rows[n].Cells["standby_2"].Value.ToString().Trim();
                                dgrow["standby_3"] = (string)dgv_asn.Rows[n].Cells["standby_3"].Value.ToString().Trim();
                                dgrow["so_status"] = "0";
                                str_sql = "  SELECT *from WMS.mst_sku where inv_org='" + main.g_org + "' and consignor='" + dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim() + "' and sku='" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim() + "' and  main_dist <> 'D'";
                                try
                                {
                                    if (main.dbtype == "SQL")
                                        ds_temp = main.dbservice.Sql_exec_selectsql(str_sql);
                                    else
                                        ds_temp = main.dbservice.oracle_exec_selectsql(str_sql);

                                    if (ds_temp.Tables[0].Rows.Count > 0) //说明有记录，默认第一条  
                                    {
                                        d_convert = 0; d_cubage = 0; d_gross_weight = 0; d_net_weight = 0;
                                        d_convert = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["convert_modulus"].ToString().Trim());
                                        str_main_unit = "";
                                        str_sub_unit = "";
                                        str_main_unit = ds_temp.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                                        str_sub_unit = ds_temp.Tables[0].Rows[0]["sub_unit"].ToString().Trim();
                                        if (str_main_unit.Trim() == str_order_unit)//单位是主数量
                                        {
                                            dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else if (str_sub_unit.Trim() == str_order_unit)//辅数量
                                        {
                                            dgrow["plan_so_qty_s"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_m"] = Math.Round(Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()) / d_convert, 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else
                                        {
                                            dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }

                                        if (ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim() != "")
                                        {
                                            d_cubage = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_cubage = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim() != "")
                                        {
                                            d_gross_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_gross_weight = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim() != "")
                                        {
                                            d_net_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_net_weight = 0;
                                        }
                                        dgrow["convert_modulus"] = d_convert.ToString();
                                        //dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["main_sub_flag"] = ds_temp.Tables[0].Rows[0]["main_sub_flag"].ToString().Trim();
                                        //dgrow["order_unit"] = ds_temp.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                                        dgrow["plan_cubage"] = Math.Round(d_cubage * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["plan_gross_weight"] = Math.Round(d_gross_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["plan_net_weight"] = Math.Round(d_net_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                    }
                                    else
                                    {
                                        //DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                                        //dr["customer_order_no"] = (string)dgv_asn.Rows[n].Cells["original_order_no"].Value.ToString().Trim();
                                        //dr["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                        //((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                        //b_temp = true;
                                    }
                                }
                                catch (System.Exception ee)
                                {
                                    MessageBox.Show("查找商品档案失败!" + ee.ToString());
                                    return;
                                }
                                ds_update.Tables[0].Rows.Add(dgrow);
                            }
                        }
                        //如果有找不到档案的就存到临时表 
                        // if (b_temp) continue;
                        try
                        {
                            if (main.dbtype == "SQL")
                                main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                            else
                                main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);


                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    DataTable dt_execl = new DataTable();
                    dt_execl.Columns.Add("customer_order_no");
                    dt_execl.Columns.Add("sku");
                    dgv_execl.DataSource = dt_execl;
                }
                progressBar1.Visible = false;
                progressBar1.Value = 0;

                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                MessageBox.Show(main.g_class.comm_getchangestring("导入成功,EXECL中有" + d_sum.ToString() + "行，导入成功" + d_count.ToString() + "行，失败" + Convert.ToString(d_sum - d_count) + "行。", main.g_info_dataset) + "!");
                #endregion
            }
            else if (main.g_class.comm_getconversestring(comboBox1.Text.Trim(), main.g_info_dataset).ToLower() == "供应商退货")
            {
                #region 保存 江森模板2
                string str_sql;
                DataSet ds_temp;
                decimal d_convert = 0, d_cubage = 0, d_gross_weight = 0, d_net_weight = 0;
                string str_main_unit = "";
                string str_sub_unit = "";
                DataSet ds_customer;

                string str_consignor_name = "", str_telephone = "", str_clerk = "";
                progressBar1.Visible = true;
                progressBar1.Maximum = dgv_asn.Rows.Count;
                progressBar1.Value = 0;
                for (int i = 0; i < dgv_asn.Rows.Count; i++)
                {
                    //如果临时表中有数据，就判断一下如果存在于临时表中的订单号就不能导入
                    bool b_temp2 = false;
                    if (dgv_execl.Rows.Count > 0)
                    {
                        for (int c = 0; c < dgv_execl.Rows.Count; c++)
                        {
                            if (dgv_asn.Rows[i].Cells["original_order_no"].Value.ToString().Trim() == dgv_execl.Rows[c].Cells["customer_order_no2"].Value.ToString().Trim())
                            {
                                b_temp2 = true;
                                break;
                            }
                        }
                    }
                    //如果已经存在临时表中，跳过这就条
                    if (b_temp2) continue;

                    string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();

                    string str_so_no = dgv_asn.Rows[i].Cells["so_no"].Value.ToString().Trim();

                    string str_so_day = dgv_asn.Rows[i].Cells["so_day"].Value.ToString().Trim();

                    string str_customer_sale_no = dgv_asn.Rows[i].Cells["customer_sale_no"].Value.ToString().Trim();

                    string str_customer_code = dgv_asn.Rows[i].Cells["customer_code"].Value.ToString().Trim();

                    string str_original_order_no = dgv_asn.Rows[i].Cells["original_order_no"].Value.ToString().Trim();

                    string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();

                    string str_pack_code = dgv_asn.Rows[i].Cells["pack_code"].Value.ToString().Trim();

                    if (dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim() == "")
                        d_plan_so_qty_m = 0;
                    else
                        d_plan_so_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);

                    if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                        d_order_price = 0;
                    else
                        d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);

                    string str_address = dgv_asn.Rows[i].Cells["address"].Value.ToString().Trim();
                    string str_lot_attribute1 = dgv_asn.Rows[i].Cells["lot_attribute1"].Value.ToString().Trim();

                    string str_lot_attribute2 = dgv_asn.Rows[i].Cells["lot_attribute2"].Value.ToString().Trim();

                    string str_lot_attribute3 = dgv_asn.Rows[i].Cells["lot_attribute3"].Value.ToString().Trim();

                    string str_lot_attribute4 = dgv_asn.Rows[i].Cells["lot_attribute4"].Value.ToString().Trim();

                    string str_lot_attribute5 = dgv_asn.Rows[i].Cells["lot_attribute5"].Value.ToString().Trim();

                    string str_lot_attribute6 = dgv_asn.Rows[i].Cells["lot_attribute6"].Value.ToString().Trim();

                    string str_lot_attribute7 = dgv_asn.Rows[i].Cells["lot_attribute7"].Value.ToString().Trim();

                    string str_lot_attribute8 = dgv_asn.Rows[i].Cells["lot_attribute8"].Value.ToString().Trim();

                    string str_lot_attribute9 = dgv_asn.Rows[i].Cells["lot_attribute9"].Value.ToString().Trim();

                    string str_lot_attribute10 = dgv_asn.Rows[i].Cells["lot_attribute10"].Value.ToString().Trim();

                    string str_lot_attribute11 = dgv_asn.Rows[i].Cells["lot_attribute11"].Value.ToString().Trim();

                    string str_lot_attribute12 = dgv_asn.Rows[i].Cells["lot_attribute12"].Value.ToString().Trim();

                    string str_lot_attribute13 = dgv_asn.Rows[i].Cells["lot_attribute13"].Value.ToString().Trim();

                    string str_lot_attribute14 = dgv_asn.Rows[i].Cells["lot_attribute14"].Value.ToString().Trim();

                    string str_lot_attribute15 = dgv_asn.Rows[i].Cells["lot_attribute15"].Value.ToString().Trim();
                    string str_order_unit = dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();
                    string str_standby_11 = dgv_asn.Rows[i].Cells["standby_11"].Value.ToString().Trim();
                    string str_standby_12 = dgv_asn.Rows[i].Cells["standby_12"].Value.ToString().Trim();
                    string str_standby_13 = dgv_asn.Rows[i].Cells["standby_13"].Value.ToString().Trim();

                    //货主是否为空
                    if (str_consignor == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                        break;
                    }
                    //判断货主是否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_customer a where a.inv_org = '" + main.g_org + "' and a.consignor ='" + str_consignor + "' and   a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where  mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }

                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Consignor is not exists or haven't privilege", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是否为空
                    if (str_sku == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    //出库单号是否为空
                    if (str_customer_sale_no == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a customer_sale_no ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    ////包装编码
                    //if (str_pack_code == "")
                    //{
                    //    MessageBox.Show(main.g_class.comm_getchangestring("Please input a pack code ", main.g_info_dataset) + "!");
                    //    dgv_asn.Rows[i].Selected = true;
                    //    break;
                    //}

                    //订货主数量是否为空
                    if (d_plan_so_qty_m == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input plan_so_qty_m ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    ////订单日期
                    //if (str_so_day == "")
                    //{
                    //    str_so_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                    //}

                    //判断表头是否存在
                    int count;
                    string str_temp1 = "select count(*) from " + main.g_space + ".so_ship_header where inv_org = '" + main.g_org + "' and consignor='" + str_consignor + "'and so_no='" + str_so_no + "'";
                    if (main.dbtype == "SQL")
                    {
                        count = main.dbservice.Sql_exec_selectint(str_temp1);
                    }
                    else
                    {
                        count = main.dbservice.oracle_exec_selectint(str_temp1);
                    }

                    if (count > 0)
                    {
                        //MessageBox.Show(main.g_class.comm_getchangestring("asn no have exists ", main.g_info_dataset) + "!" + str_consignor + "/" + str_asn_no);
                        //dgv_asn.Rows.Remove(dgv_asn.Rows[dgv_asn.Rows[i].Index]);
                        continue;
                    }
                    else
                    {
                        //str_so_no = main.g_class.comm_getaccountno("so_no");
                        //if (str_address.Trim() == "")
                        //{
                        if (str_customer_code.Trim() != "")
                        {
                            str_sql = "select consignor_name,business_address,telephone,clerk from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and consignor = '" + str_customer_code.Trim() + "'";
                            if (main.dbtype == "SQL")
                            {
                                ds_customer = main.dbservice.Sql_exec_selectsql(str_sql);
                            }
                            else
                            {
                                ds_customer = main.dbservice.oracle_exec_selectsql(str_sql);
                            }
                            if (ds_customer.Tables[0].Rows.Count > 0) //说明有数据
                            {
                                str_consignor_name = ds_customer.Tables[0].Rows[0]["consignor_name"].ToString().Trim();
                                str_telephone = "";
                                str_clerk = "";

                                //str_telephone = ds_customer.Tables[0].Rows[0]["telephone"].ToString().Trim();
                                //str_clerk = ds_customer.Tables[0].Rows[0]["clerk"].ToString().Trim();
                                //if (str_telephone.Length > 20)
                                //{
                                //    str_telephone = str_telephone.Substring(0, 19);
                                //}
                                //if (str_address.Trim() == "")
                                //{
                                //    str_address = ds_customer.Tables[0].Rows[0]["business_address"].ToString().Trim();
                                //}
                            }
                            else
                            {
                                str_consignor_name = "";
                                str_telephone = "";
                                str_clerk = "";
                            }
                        }
                        //}
                        string str_insert;
                        if (main.dbtype == "SQL")
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                        " so_flag,so_status,main_dist,made_time,maker,rush_flag,cross_flag,so_prior,wave_flag,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12,standby_13)  " +
                                                            " values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                    "'" + str_customer_code + "','" + str_original_order_no + "','1','0','0','A', getdate(),'" + main.g_user + "','0','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_clerk + "','" + str_consignor_name + "','" + str_standby_11.Trim() + "','" + str_standby_12.Trim() + "','" + str_standby_13.Trim() + "')";
                        }
                        else
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                         " so_flag,so_status,main_dist,made_time,maker,,rush_flag,cross_flag,so_prior,wave_flag ,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12,standby_13)  " +
                                                             "  values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                      "'" + str_customer_code + "','" + str_original_order_no + "','1','0','0','A', sysdate,'" + main.g_user + "','0','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_clerk + "','" + str_consignor_name + "','" + str_standby_11.Trim() + "','" + str_standby_12.Trim() + "','" + str_standby_13.Trim() + "')";
                        }

                        int k = 0;
                        ds_update.Tables[0].Clear();
                        //bool b_temp = false;
                        for (int n = 0; n < dgv_asn.Rows.Count; n++)
                        {
                            str_oldno = dgv_asn.Rows[n].Cells["so_no"].Value.ToString().Trim();
                            str_oldconsignor = dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                            if (str_oldno == str_so_no && str_oldconsignor == str_consignor)
                            {
                                DataRow dgrow;
                                k = k + 1;
                                dgrow = ds_update.Tables[0].NewRow();
                                dgrow["inv_org"] = main.g_org;
                                dgrow["consignor"] = (string)dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                                dgrow["so_no"] = str_so_no;
                                dgrow["so_line_no"] = k;
                                dgrow["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                //根据SKU找出包装和单位
                                //DataSet ds_temp2;
                                //string str_sql2;

                                dgrow["pack_code"] = (string)dgv_asn.Rows[n].Cells["pack_code"].Value.ToString().Trim();

                                str_order_unit = (string)dgv_asn.Rows[n].Cells["order_unit"].Value.ToString().Trim();
                                //dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                dgrow["order_price"] = (string)dgv_asn.Rows[n].Cells["order_price"].Value.ToString().Trim();
                                dgrow["lot_attribute1"] = (string)dgv_asn.Rows[n].Cells["lot_attribute1"].Value.ToString().Trim();
                                dgrow["lot_attribute2"] = (string)dgv_asn.Rows[n].Cells["lot_attribute2"].Value.ToString().Trim();
                                dgrow["lot_attribute3"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                dgrow["lot_attribute4"] = (string)dgv_asn.Rows[n].Cells["lot_attribute4"].Value.ToString().Trim();
                                dgrow["lot_attribute5"] = (string)dgv_asn.Rows[n].Cells["lot_attribute5"].Value.ToString().Trim();
                                dgrow["lot_attribute6"] = (string)dgv_asn.Rows[n].Cells["lot_attribute6"].Value.ToString().Trim();
                                dgrow["lot_attribute7"] = (string)dgv_asn.Rows[n].Cells["lot_attribute7"].Value.ToString().Trim();
                                dgrow["lot_attribute8"] = (string)dgv_asn.Rows[n].Cells["lot_attribute8"].Value.ToString().Trim();
                                dgrow["lot_attribute9"] = (string)dgv_asn.Rows[n].Cells["lot_attribute9"].Value.ToString().Trim();
                                dgrow["lot_attribute10"] = (string)dgv_asn.Rows[n].Cells["lot_attribute10"].Value.ToString().Trim();
                                dgrow["lot_attribute11"] = (string)dgv_asn.Rows[n].Cells["lot_attribute11"].Value.ToString().Trim();
                                dgrow["lot_attribute12"] = (string)dgv_asn.Rows[n].Cells["lot_attribute12"].Value.ToString().Trim();
                                dgrow["lot_attribute13"] = (string)dgv_asn.Rows[n].Cells["lot_attribute13"].Value.ToString().Trim();
                                dgrow["lot_attribute14"] = (string)dgv_asn.Rows[n].Cells["lot_attribute14"].Value.ToString().Trim();
                                dgrow["lot_attribute15"] = (string)dgv_asn.Rows[n].Cells["lot_attribute15"].Value.ToString().Trim();
                                dgrow["main_dist"] = "A";
                                dgrow["made_time"] = (string)DateTime.Now.ToString("yyyy.MM.dd").Trim();
                                dgrow["maker"] = main.g_user;

                                dgrow["ship_qty_m"] = 0;
                                dgrow["ship_qty_s"] = 0;
                                dgrow["standby_6"] = 0;
                                dgrow["standby_7"] = 0;
                                dgrow["so_status"] = "0";
                                str_sql = "  SELECT *from WMS.mst_sku where inv_org='" + main.g_org + "' and consignor='" + dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim() + "' and sku='" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim() + "' and  main_dist <> 'D'";
                                try
                                {
                                    if (main.dbtype == "SQL")
                                        ds_temp = main.dbservice.Sql_exec_selectsql(str_sql);
                                    else
                                        ds_temp = main.dbservice.oracle_exec_selectsql(str_sql);

                                    if (ds_temp.Tables[0].Rows.Count > 0) //说明有记录，默认第一条  
                                    {
                                        d_convert = 0; d_cubage = 0; d_gross_weight = 0; d_net_weight = 0;
                                        d_convert = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["convert_modulus"].ToString().Trim());
                                        str_main_unit = "";
                                        str_sub_unit = "";
                                        str_main_unit = ds_temp.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                                        str_sub_unit = ds_temp.Tables[0].Rows[0]["sub_unit"].ToString().Trim();
                                        if (str_main_unit.Trim() == str_order_unit)//单位是主数量
                                        {
                                            dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else if (str_sub_unit.Trim() == str_order_unit)//辅数量
                                        {
                                            dgrow["plan_so_qty_s"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_m"] = Math.Round(Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()) / d_convert, 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else
                                        {
                                            dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }

                                        if (ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim() != "")
                                        {
                                            d_cubage = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_cubage = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim() != "")
                                        {
                                            d_gross_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_gross_weight = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim() != "")
                                        {
                                            d_net_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_net_weight = 0;
                                        }
                                        dgrow["convert_modulus"] = d_convert.ToString();
                                        //dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["main_sub_flag"] = ds_temp.Tables[0].Rows[0]["main_sub_flag"].ToString().Trim();
                                        //dgrow["order_unit"] = ds_temp.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                                        dgrow["plan_cubage"] = Math.Round(d_cubage * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["plan_gross_weight"] = Math.Round(d_gross_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["plan_net_weight"] = Math.Round(d_net_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                    }
                                    else
                                    {
                                        //DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                                        //dr["customer_order_no"] = (string)dgv_asn.Rows[n].Cells["original_order_no"].Value.ToString().Trim();
                                        //dr["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                        //((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                        //b_temp = true;
                                    }
                                }
                                catch (System.Exception ee)
                                {
                                    MessageBox.Show("查找商品档案失败!" + ee.ToString());
                                    return;
                                }
                                ds_update.Tables[0].Rows.Add(dgrow);
                            }
                        }
                        //如果有找不到档案的就存到临时表 
                        // if (b_temp) continue;
                        try
                        {
                            if (main.dbtype == "SQL")
                                main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                            else
                                main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);


                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    DataTable dt_execl = new DataTable();
                    dt_execl.Columns.Add("customer_order_no");
                    dt_execl.Columns.Add("sku");
                    dgv_execl.DataSource = dt_execl;
                }
                progressBar1.Visible = false;
                progressBar1.Value = 0;

                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                MessageBox.Show(main.g_class.comm_getchangestring("导入成功,EXECL中有" + d_sum.ToString() + "行，导入成功" + d_count.ToString() + "行，失败" + Convert.ToString(d_sum - d_count) + "行。", main.g_info_dataset) + "!");
                #endregion
            }
            else if (main.g_class.comm_getconversestring(comboBox1.Text.Trim(), main.g_info_dataset).ToLower() == "出口出货单")
            {
                #region 保存 转口出货单
                string str_sql;
                DataSet ds_temp;
                decimal d_convert = 0, d_cubage = 0, d_gross_weight = 0, d_net_weight = 0;
                string str_main_unit = "";
                string str_sub_unit = "";
                DataSet ds_customer;

                string str_telephone = "", str_clerk = "";
                progressBar1.Visible = true;
                progressBar1.Maximum = dgv_asn.Rows.Count;
                progressBar1.Value = 0;

                for (int i = 0; i < dgv_asn.Rows.Count; i++)
                {
                    //如果临时表中有数据，就判断一下如果存在于临时表中的订单号就不能导入
                    bool b_temp2 = false;
                    if (dgv_execl.Rows.Count > 0)
                    {
                        for (int c = 0; c < dgv_execl.Rows.Count; c++)
                        {
                            if (dgv_asn.Rows[i].Cells["original_order_no"].Value.ToString().Trim() == dgv_execl.Rows[c].Cells["customer_order_no2"].Value.ToString().Trim())
                            {
                                b_temp2 = true;
                                break;
                            }
                        }
                    }
                    //如果已经存在临时表中，跳过这就条
                    if (b_temp2) continue;

                    string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();

                    string str_so_no = dgv_asn.Rows[i].Cells["so_no"].Value.ToString().Trim();

                    string str_so_day = dgv_asn.Rows[i].Cells["so_day"].Value.ToString().Trim();

                    string str_customer_sale_no = dgv_asn.Rows[i].Cells["customer_sale_no"].Value.ToString().Trim();

                    string str_customer_code = dgv_asn.Rows[i].Cells["customer_code"].Value.ToString().Trim();

                    string str_customer_name = dgv_asn.Rows[i].Cells["customer_name"].Value.ToString().Trim();

                    string str_original_order_no = dgv_asn.Rows[i].Cells["original_order_no"].Value.ToString().Trim();

                    string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();

                    string str_pack_code = dgv_asn.Rows[i].Cells["pack_code"].Value.ToString().Trim();

                    if (dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim() == "")
                        d_plan_so_qty_m = 0;
                    else
                        d_plan_so_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);

                    if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                        d_order_price = 0;
                    else
                        d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);

                    string str_address = dgv_asn.Rows[i].Cells["address"].Value.ToString().Trim();
                    string str_lot_attribute1 = dgv_asn.Rows[i].Cells["lot_attribute1"].Value.ToString().Trim();

                    string str_lot_attribute2 = dgv_asn.Rows[i].Cells["lot_attribute2"].Value.ToString().Trim();

                    string str_lot_attribute3 = dgv_asn.Rows[i].Cells["lot_attribute3"].Value.ToString().Trim();

                    string str_lot_attribute4 = dgv_asn.Rows[i].Cells["lot_attribute4"].Value.ToString().Trim();

                    string str_lot_attribute5 = dgv_asn.Rows[i].Cells["lot_attribute5"].Value.ToString().Trim();

                    string str_lot_attribute6 = dgv_asn.Rows[i].Cells["lot_attribute6"].Value.ToString().Trim();

                    string str_lot_attribute7 = dgv_asn.Rows[i].Cells["lot_attribute7"].Value.ToString().Trim();

                    string str_lot_attribute8 = dgv_asn.Rows[i].Cells["lot_attribute8"].Value.ToString().Trim();

                    string str_lot_attribute9 = dgv_asn.Rows[i].Cells["lot_attribute9"].Value.ToString().Trim();

                    string str_lot_attribute10 = dgv_asn.Rows[i].Cells["lot_attribute10"].Value.ToString().Trim();

                    string str_lot_attribute11 = dgv_asn.Rows[i].Cells["lot_attribute11"].Value.ToString().Trim();

                    string str_lot_attribute12 = dgv_asn.Rows[i].Cells["lot_attribute12"].Value.ToString().Trim();

                    string str_lot_attribute13 = dgv_asn.Rows[i].Cells["lot_attribute13"].Value.ToString().Trim();

                    string str_lot_attribute14 = dgv_asn.Rows[i].Cells["lot_attribute14"].Value.ToString().Trim();

                    string str_lot_attribute15 = dgv_asn.Rows[i].Cells["lot_attribute15"].Value.ToString().Trim();
                    string str_order_unit = dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();
                    string str_standby_11 = dgv_asn.Rows[i].Cells["standby_11"].Value.ToString().Trim();
                    string str_standby_12 = dgv_asn.Rows[i].Cells["standby_12"].Value.ToString().Trim();
                    string str_standby_13 = dgv_asn.Rows[i].Cells["standby_13"].Value.ToString().Trim();
                    string str_standby_14 = dgv_asn.Rows[i].Cells["standby_14"].Value.ToString().Trim();
                    string str_area_code = dgv_asn.Rows[i].Cells["area_code"].Value.ToString().Trim(); 
                    str_clerk = dgv_asn.Rows[i].Cells["receiver"].Value.ToString().Trim();
                    //货主是否为空
                    if (str_consignor == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                        break;
                    }
                    //判断货主是否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_customer a where a.inv_org = '" + main.g_org + "' and a.consignor ='" + str_consignor + "' and   a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where  mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }

                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Consignor is not exists or haven't privilege", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是否为空
                    if (str_sku == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    //出库单号是否为空
                    if (str_customer_sale_no == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a customer_sale_no ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    ////包装编码
                    //if (str_pack_code == "")
                    //{
                    //    MessageBox.Show(main.g_class.comm_getchangestring("Please input a pack code ", main.g_info_dataset) + "!");
                    //    dgv_asn.Rows[i].Selected = true;
                    //    break;
                    //}

                    //订货主数量是否为空
                    if (d_plan_so_qty_m == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input plan_so_qty_m ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    ////订单日期
                    //if (str_so_day == "")
                    //{
                    //    str_so_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                    //}

                    //判断表头是否存在
                    int count;
                    string str_temp1 = "select count(*) from " + main.g_space + ".so_ship_header where inv_org = '" + main.g_org + "' and consignor='" + str_consignor + "'and so_no='" + str_so_no + "'";
                    if (main.dbtype == "SQL")
                    {
                        count = main.dbservice.Sql_exec_selectint(str_temp1);
                    }
                    else
                    {
                        count = main.dbservice.oracle_exec_selectint(str_temp1);
                    }

                    if (count > 0)
                    {
                        //MessageBox.Show(main.g_class.comm_getchangestring("asn no have exists ", main.g_info_dataset) + "!" + str_consignor + "/" + str_asn_no);
                        //dgv_asn.Rows.Remove(dgv_asn.Rows[dgv_asn.Rows[i].Index]);
                        continue;
                    }
                    else
                    {
                        //str_so_no = main.g_class.comm_getaccountno("so_no");

                        if (str_customer_code.Trim() != "")
                        {
                            str_sql = "select consignor_name,business_address,telephone,clerk from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and consignor = '" + str_customer_code.Trim() + "'";
                            if (main.dbtype == "SQL")
                            {
                                ds_customer = main.dbservice.Sql_exec_selectsql(str_sql);
                            }
                            else
                            {
                                ds_customer = main.dbservice.oracle_exec_selectsql(str_sql);
                            }
                            if (ds_customer.Tables[0].Rows.Count > 0) //说明有数据
                            {
                                //str_consignor_name = ds_customer.Tables[0].Rows[0]["consignor_name"].ToString().Trim();
                                str_telephone = ds_customer.Tables[0].Rows[0]["telephone"].ToString().Trim();
                                //str_clerk = ds_customer.Tables[0].Rows[0]["clerk"].ToString().Trim();
                                if (str_telephone.Length > 20)
                                {
                                    str_telephone = str_telephone.Substring(0, 19);
                                }
                                //if (str_address.Trim() == "")
                                //{
                                //    str_address = ds_customer.Tables[0].Rows[0]["business_address"].ToString().Trim();
                                //}
                            }
                            else
                            {
                                // str_consignor_name = "";
                                str_telephone = "";
                                str_clerk = "";
                            }
                        }
                        string str_insert;
                        if (main.dbtype == "SQL")
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                        " so_flag,so_status,main_dist,made_time,maker,rush_flag,cross_flag,so_prior,wave_flag,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12,standby_13,standby_14,area_code)  " +
                                                            " values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                    "'" + str_customer_code + "','" + str_original_order_no + "','5','0','0','A', getdate(),'" + main.g_user + "','0','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_clerk + "','" + str_customer_name + "','" + str_standby_11.Trim() + "','" + str_standby_12.Trim() + "','" + str_standby_13.Trim() + "','" + str_standby_14.Trim() + "','"+str_area_code+"' )";
                        }
                        else
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                         " so_flag,so_status,main_dist,made_time,maker,,rush_flag,cross_flag,so_prior,wave_flag ,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12,standby_13,standby_14,area_code)  " +
                                                             "  values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                      "'" + str_customer_code + "','" + str_original_order_no + "','5','0','0','A', sysdate,'" + main.g_user + "','0','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_clerk + "','" + str_customer_name + "','" + str_standby_11.Trim() + "','" + str_standby_12.Trim() + "','" + str_standby_13.Trim() + "','" + str_standby_14.Trim() + "','" + str_area_code + "' )";
                        }

                        int k = 0;
                        ds_update.Tables[0].Clear();
                        //bool b_temp = false;
                        for (int n = 0; n < dgv_asn.Rows.Count; n++)
                        {
                            str_oldno = dgv_asn.Rows[n].Cells["so_no"].Value.ToString().Trim();
                            str_oldconsignor = dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                            if (str_oldno == str_so_no && str_oldconsignor == str_consignor)
                            {
                                DataRow dgrow;
                                k = k + 1;
                                dgrow = ds_update.Tables[0].NewRow();
                                dgrow["inv_org"] = main.g_org;
                                dgrow["consignor"] = (string)dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                                dgrow["so_no"] = str_so_no;
                                dgrow["so_line_no"] = k;
                                dgrow["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                //根据SKU找出包装和单位
                                //DataSet ds_temp2;
                                //string str_sql2;

                                dgrow["pack_code"] = (string)dgv_asn.Rows[n].Cells["pack_code"].Value.ToString().Trim();

                                str_order_unit = (string)dgv_asn.Rows[n].Cells["order_unit"].Value.ToString().Trim();
                                //dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                dgrow["order_price"] = (string)dgv_asn.Rows[n].Cells["order_price"].Value.ToString().Trim();
                                dgrow["lot_attribute1"] = (string)dgv_asn.Rows[n].Cells["lot_attribute1"].Value.ToString().Trim();
                                dgrow["lot_attribute2"] = (string)dgv_asn.Rows[n].Cells["lot_attribute2"].Value.ToString().Trim();
                                dgrow["lot_attribute3"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                dgrow["lot_attribute4"] = (string)dgv_asn.Rows[n].Cells["lot_attribute4"].Value.ToString().Trim();
                                dgrow["lot_attribute5"] = (string)dgv_asn.Rows[n].Cells["lot_attribute5"].Value.ToString().Trim();
                                dgrow["lot_attribute6"] = (string)dgv_asn.Rows[n].Cells["lot_attribute6"].Value.ToString().Trim();
                                dgrow["lot_attribute7"] = (string)dgv_asn.Rows[n].Cells["lot_attribute7"].Value.ToString().Trim();
                                dgrow["lot_attribute8"] = (string)dgv_asn.Rows[n].Cells["lot_attribute8"].Value.ToString().Trim();
                                dgrow["lot_attribute9"] = (string)dgv_asn.Rows[n].Cells["lot_attribute9"].Value.ToString().Trim();
                                dgrow["lot_attribute10"] = (string)dgv_asn.Rows[n].Cells["lot_attribute10"].Value.ToString().Trim();
                                dgrow["lot_attribute11"] = (string)dgv_asn.Rows[n].Cells["lot_attribute11"].Value.ToString().Trim();
                                dgrow["lot_attribute12"] = (string)dgv_asn.Rows[n].Cells["lot_attribute12"].Value.ToString().Trim();
                                dgrow["lot_attribute13"] = (string)dgv_asn.Rows[n].Cells["lot_attribute13"].Value.ToString().Trim();
                                dgrow["lot_attribute14"] = (string)dgv_asn.Rows[n].Cells["lot_attribute14"].Value.ToString().Trim();
                                dgrow["lot_attribute15"] = (string)dgv_asn.Rows[n].Cells["lot_attribute15"].Value.ToString().Trim();
                                dgrow["main_dist"] = "A";
                                dgrow["made_time"] = (string)DateTime.Now.ToString("yyyy.MM.dd").Trim();
                                dgrow["maker"] = main.g_user;

                                dgrow["ship_qty_m"] = 0;
                                dgrow["ship_qty_s"] = 0;
                                dgrow["standby_2"] = (string)dgv_asn.Rows[n].Cells["standby_2"].Value.ToString().Trim();
                                dgrow["standby_3"] = (string)dgv_asn.Rows[n].Cells["standby_3"].Value.ToString().Trim();
                                dgrow["standby_6"] = 0;
                                dgrow["standby_7"] = 0;
                                dgrow["so_status"] = "0";
                                str_sql = "  SELECT *from "+main.g_space+".mst_sku where inv_org='" + main.g_org + "' and consignor='" + dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim() + "' and sku='" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim() + "' and  main_dist <> 'D'";
                                try
                                {
                                    if (main.dbtype == "SQL")
                                        ds_temp = main.dbservice.Sql_exec_selectsql(str_sql);
                                    else
                                        ds_temp = main.dbservice.oracle_exec_selectsql(str_sql);

                                    if (ds_temp.Tables[0].Rows.Count > 0) //说明有记录，默认第一条  
                                    {
                                        d_convert = 0; d_cubage = 0; d_gross_weight = 0; d_net_weight = 0;
                                        d_convert = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["convert_modulus"].ToString().Trim());
                                        str_main_unit = "";
                                        str_sub_unit = "";
                                        str_main_unit = ds_temp.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                                        str_sub_unit = ds_temp.Tables[0].Rows[0]["sub_unit"].ToString().Trim();
                                        if (str_main_unit.Trim() == str_order_unit)//单位是主数量
                                        {
                                            dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else if (str_sub_unit.Trim() == str_order_unit)//辅数量
                                        {
                                            dgrow["plan_so_qty_s"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_m"] = Math.Round(Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()) / d_convert, 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else
                                        {
                                            dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }

                                        if (ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim() != "")
                                        {
                                            d_cubage = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_cubage = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim() != "")
                                        {
                                            d_gross_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_gross_weight = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim() != "")
                                        {
                                            d_net_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_net_weight = 0;
                                        }
                                        dgrow["convert_modulus"] = d_convert.ToString();
                                        //dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["main_sub_flag"] = ds_temp.Tables[0].Rows[0]["main_sub_flag"].ToString().Trim();
                                        //dgrow["order_unit"] = ds_temp.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                                        dgrow["plan_cubage"] = Math.Round(d_cubage * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["plan_gross_weight"] = Math.Round(d_gross_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["plan_net_weight"] = Math.Round(d_net_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                    }
                                    else
                                    {
                                        //DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                                        //dr["customer_order_no"] = (string)dgv_asn.Rows[n].Cells["original_order_no"].Value.ToString().Trim();
                                        //dr["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                        //((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                        //b_temp = true;
                                    }
                                }
                                catch (System.Exception ee)
                                {
                                    MessageBox.Show("查找商品档案失败!" + ee.ToString());
                                    return;
                                }
                                ds_update.Tables[0].Rows.Add(dgrow);
                            }
                        }
                        //如果有找不到档案的就存到临时表 
                        // if (b_temp) continue;
                        try
                        {
                            if (main.dbtype == "SQL")
                                main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                            else
                                main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);


                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    DataTable dt_execl = new DataTable();
                    dt_execl.Columns.Add("customer_order_no");
                    dt_execl.Columns.Add("sku");
                    dgv_execl.DataSource = dt_execl;
                }
                progressBar1.Visible = false;
                progressBar1.Value = 0;

                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                MessageBox.Show(main.g_class.comm_getchangestring("导入成功,EXECL中有" + d_sum.ToString() + "行，导入成功" + d_count.ToString() + "行，失败" + Convert.ToString(d_sum - d_count) + "行。", main.g_info_dataset) + "!");
                #endregion
            }
            else if (main.g_class.comm_getconversestring(comboBox1.Text.Trim(), main.g_info_dataset).ToLower() == "sh office")
            {
                #region 保存 sh office
                string str_sql;
                DataSet ds_temp;
                decimal d_convert = 0, d_cubage = 0, d_gross_weight = 0, d_net_weight = 0;
                string str_main_unit = "";
                string str_sub_unit = "";
                DataSet ds_customer;   

                string str_consignor_name = "", str_telephone = "", str_clerk = "";
                progressBar1.Visible = true;
                progressBar1.Maximum = dgv_asn.Rows.Count;
                progressBar1.Value = 0;
                for (int i = 0; i < dgv_asn.Rows.Count; i++)
                {
                    //如果临时表中有数据，就判断一下如果存在于临时表中的订单号就不能导入
                    bool b_temp2 = false;
                    if (dgv_execl.Rows.Count > 0)
                    {
                        for (int c = 0; c < dgv_execl.Rows.Count; c++)
                        {
                            if (dgv_asn.Rows[i].Cells["original_order_no"].Value.ToString().Trim() == dgv_execl.Rows[c].Cells["customer_order_no2"].Value.ToString().Trim())
                            {
                                b_temp2 = true;
                                break;
                            }
                        }
                    }
                    //如果已经存在临时表中，跳过这就条
                    if (b_temp2) continue;

                    string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();

                    string str_so_no = dgv_asn.Rows[i].Cells["so_no"].Value.ToString().Trim();

                    string str_so_day = dgv_asn.Rows[i].Cells["so_day"].Value.ToString().Trim();

                    string str_customer_sale_no = dgv_asn.Rows[i].Cells["customer_sale_no"].Value.ToString().Trim();

                    string str_customer_code = dgv_asn.Rows[i].Cells["customer_code"].Value.ToString().Trim();

                    string str_original_order_no = dgv_asn.Rows[i].Cells["original_order_no"].Value.ToString().Trim();

                    string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();

                    string str_pack_code = dgv_asn.Rows[i].Cells["pack_code"].Value.ToString().Trim();

                    if (dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim() == "")
                        d_plan_so_qty_m = 0;
                    else
                        d_plan_so_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);

                    if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                        d_order_price = 0;
                    else
                        d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);

                    string str_address = dgv_asn.Rows[i].Cells["address"].Value.ToString().Trim();
                    string str_lot_attribute1 = dgv_asn.Rows[i].Cells["lot_attribute1"].Value.ToString().Trim();

                    string str_lot_attribute2 = dgv_asn.Rows[i].Cells["lot_attribute2"].Value.ToString().Trim();

                    string str_lot_attribute3 = dgv_asn.Rows[i].Cells["lot_attribute3"].Value.ToString().Trim();

                    string str_lot_attribute4 = dgv_asn.Rows[i].Cells["lot_attribute4"].Value.ToString().Trim();

                    string str_lot_attribute5 = dgv_asn.Rows[i].Cells["lot_attribute5"].Value.ToString().Trim();

                    string str_lot_attribute6 = dgv_asn.Rows[i].Cells["lot_attribute6"].Value.ToString().Trim();

                    string str_lot_attribute7 = dgv_asn.Rows[i].Cells["lot_attribute7"].Value.ToString().Trim();

                    string str_lot_attribute8 = dgv_asn.Rows[i].Cells["lot_attribute8"].Value.ToString().Trim();

                    string str_lot_attribute9 = dgv_asn.Rows[i].Cells["lot_attribute9"].Value.ToString().Trim();

                    string str_lot_attribute10 = dgv_asn.Rows[i].Cells["lot_attribute10"].Value.ToString().Trim();

                    string str_lot_attribute11 = dgv_asn.Rows[i].Cells["lot_attribute11"].Value.ToString().Trim();

                    string str_lot_attribute12 = dgv_asn.Rows[i].Cells["lot_attribute12"].Value.ToString().Trim();

                    string str_lot_attribute13 = dgv_asn.Rows[i].Cells["lot_attribute13"].Value.ToString().Trim();

                    string str_lot_attribute14 = dgv_asn.Rows[i].Cells["lot_attribute14"].Value.ToString().Trim();

                    string str_lot_attribute15 = dgv_asn.Rows[i].Cells["lot_attribute15"].Value.ToString().Trim();
                    string str_order_unit = dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();
                    string str_standby_11 = dgv_asn.Rows[i].Cells["standby_11"].Value.ToString().Trim();
                    string str_standby_12 = dgv_asn.Rows[i].Cells["standby_12"].Value.ToString().Trim();
                    string str_standby_13 = dgv_asn.Rows[i].Cells["standby_13"].Value.ToString().Trim();
                    str_address = dgv_asn.Rows[i].Cells["address"].Value.ToString().Trim();
                    //货主是否为空
                    if (str_consignor == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                        break;
                    }
                    //判断货主是否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_customer a where a.inv_org = '" + main.g_org + "' and a.consignor ='" + str_consignor + "' and   a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where  mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }

                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Consignor is not exists or haven't privilege", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是否为空
                    if (str_sku == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    //出库单号是否为空
                    if (str_customer_sale_no == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a customer_sale_no ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }

                    ////包装编码
                    //if (str_pack_code == "")
                    //{
                    //    MessageBox.Show(main.g_class.comm_getchangestring("Please input a pack code ", main.g_info_dataset) + "!");
                    //    dgv_asn.Rows[i].Selected = true;
                    //    break;
                    //}

                    //订货主数量是否为空
                    if (d_plan_so_qty_m == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input plan_so_qty_m ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    ////订单日期
                    //if (str_so_day == "")
                    //{
                    //    str_so_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                    //}

                    //判断表头是否存在
                    int count;
                    string str_temp1 = "select count(*) from " + main.g_space + ".so_ship_header where inv_org = '" + main.g_org + "' and consignor='" + str_consignor + "'and so_no='" + str_so_no + "'";
                    if (main.dbtype == "SQL")
                    {
                        count = main.dbservice.Sql_exec_selectint(str_temp1);
                    }
                    else
                    {
                        count = main.dbservice.oracle_exec_selectint(str_temp1);
                    }

                    if (count > 0)
                    {
                        //MessageBox.Show(main.g_class.comm_getchangestring("asn no have exists ", main.g_info_dataset) + "!" + str_consignor + "/" + str_asn_no);
                        //dgv_asn.Rows.Remove(dgv_asn.Rows[dgv_asn.Rows[i].Index]);
                        continue;
                    }
                    else
                    {
                        //str_so_no = main.g_class.comm_getaccountno("so_no");

                        if (str_customer_code.Trim() != "")
                        {
                            str_sql = "select consignor_name,business_address,telephone,clerk from " + main.g_space + ".mst_customer where inv_org = '" + main.g_org + "' and consignor = '" + str_customer_code.Trim() + "'";
                            if (main.dbtype == "SQL")
                            {
                                ds_customer = main.dbservice.Sql_exec_selectsql(str_sql);
                            }
                            else
                            {
                                ds_customer = main.dbservice.oracle_exec_selectsql(str_sql);
                            }
                            if (ds_customer.Tables[0].Rows.Count > 0) //说明有数据
                            {
                                str_consignor_name = ds_customer.Tables[0].Rows[0]["consignor_name"].ToString().Trim();
                                //str_telephone = "";
                                //str_clerk = "";
                                str_telephone = ds_customer.Tables[0].Rows[0]["telephone"].ToString().Trim();
                                str_clerk = ds_customer.Tables[0].Rows[0]["clerk"].ToString().Trim();
                                //if (str_telephone.Length > 20)
                                //{
                                //    str_telephone = str_telephone.Substring(0, 19);
                                //}
                                //if (str_address.Trim() == "")
                                //{
                                //    str_address = ds_customer.Tables[0].Rows[0]["business_address"].ToString().Trim();
                                //}
                            }
                            else
                            {
                                str_consignor_name = "";
                                str_telephone = "";
                                str_clerk = "";
                            }
                        }
                        string str_insert;
                        if (main.dbtype == "SQL")
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                        " so_flag,so_status,main_dist,made_time,maker,rush_flag,cross_flag,so_prior,wave_flag,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12,standby_13)  " +
                                                            " values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                    "'" + str_customer_code + "','" + str_original_order_no + "','0','0','0','A', getdate(),'" + main.g_user + "','0','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_clerk + "','" + str_consignor_name + "','" + str_standby_11.Trim() + "','" + str_standby_12.Trim() + "','" + str_standby_13.Trim() + "')";
                        }
                        else
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                         " so_flag,so_status,main_dist,made_time,maker,,rush_flag,cross_flag,so_prior,wave_flag ,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12,standby_13)  " +
                                                             "  values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                      "'" + str_customer_code + "','" + str_original_order_no + "','0','0','0','A', sysdate,'" + main.g_user + "','0','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_clerk + "','" + str_consignor_name + "','" + str_standby_11.Trim() + "','" + str_standby_12.Trim() + "','" + str_standby_13.Trim() + "')";
                        }

                        int k = 0;
                        ds_update.Tables[0].Clear();
                        //bool b_temp = false;
                        for (int n = 0; n < dgv_asn.Rows.Count; n++)
                        {
                            str_oldno = dgv_asn.Rows[n].Cells["so_no"].Value.ToString().Trim();
                            str_oldconsignor = dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                            if (str_oldno == str_so_no && str_oldconsignor == str_consignor)
                            {
                                DataRow dgrow;
                                k = k + 1;
                                dgrow = ds_update.Tables[0].NewRow();
                                dgrow["inv_org"] = main.g_org;
                                dgrow["consignor"] = (string)dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                                dgrow["so_no"] = str_so_no;
                                dgrow["so_line_no"] = k;
                                dgrow["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                //根据SKU找出包装和单位
                                //DataSet ds_temp2;
                                //string str_sql2;

                                dgrow["pack_code"] = (string)dgv_asn.Rows[n].Cells["pack_code"].Value.ToString().Trim();

                                str_order_unit = (string)dgv_asn.Rows[n].Cells["order_unit"].Value.ToString().Trim();
                                //dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                dgrow["order_price"] = (string)dgv_asn.Rows[n].Cells["order_price"].Value.ToString().Trim();
                                dgrow["lot_attribute1"] = (string)dgv_asn.Rows[n].Cells["lot_attribute1"].Value.ToString().Trim();
                                dgrow["lot_attribute2"] = (string)dgv_asn.Rows[n].Cells["lot_attribute2"].Value.ToString().Trim();
                                dgrow["lot_attribute3"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                dgrow["lot_attribute4"] = (string)dgv_asn.Rows[n].Cells["lot_attribute4"].Value.ToString().Trim();
                                dgrow["lot_attribute5"] = (string)dgv_asn.Rows[n].Cells["lot_attribute5"].Value.ToString().Trim();
                                dgrow["lot_attribute6"] = (string)dgv_asn.Rows[n].Cells["lot_attribute6"].Value.ToString().Trim();
                                dgrow["lot_attribute7"] = (string)dgv_asn.Rows[n].Cells["lot_attribute7"].Value.ToString().Trim();
                                dgrow["lot_attribute8"] = (string)dgv_asn.Rows[n].Cells["lot_attribute8"].Value.ToString().Trim();
                                dgrow["lot_attribute9"] = (string)dgv_asn.Rows[n].Cells["lot_attribute9"].Value.ToString().Trim();
                                dgrow["lot_attribute10"] = (string)dgv_asn.Rows[n].Cells["lot_attribute10"].Value.ToString().Trim();
                                dgrow["lot_attribute11"] = (string)dgv_asn.Rows[n].Cells["lot_attribute11"].Value.ToString().Trim();
                                dgrow["lot_attribute12"] = (string)dgv_asn.Rows[n].Cells["lot_attribute12"].Value.ToString().Trim();
                                dgrow["lot_attribute13"] = (string)dgv_asn.Rows[n].Cells["lot_attribute13"].Value.ToString().Trim();
                                dgrow["lot_attribute14"] = (string)dgv_asn.Rows[n].Cells["lot_attribute14"].Value.ToString().Trim();
                                dgrow["lot_attribute15"] = (string)dgv_asn.Rows[n].Cells["lot_attribute15"].Value.ToString().Trim();
                                dgrow["main_dist"] = "A";
                                dgrow["made_time"] = (string)DateTime.Now.ToString("yyyy.MM.dd").Trim();
                                dgrow["maker"] = main.g_user;
                                dgrow["standby_3"] = (string)dgv_asn.Rows[n].Cells["standby_3"].Value.ToString().Trim();
                                dgrow["ship_qty_m"] = 0;
                                dgrow["ship_qty_s"] = 0;
                                dgrow["standby_6"] = 0;
                                dgrow["standby_7"] = 0;
                                dgrow["so_status"] = "0";
                                str_sql = "  SELECT *from WMS.mst_sku where inv_org='" + main.g_org + "' and consignor='" + dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim() + "' and sku='" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim() + "' and  main_dist <> 'D'";
                                try
                                {
                                    if (main.dbtype == "SQL")
                                        ds_temp = main.dbservice.Sql_exec_selectsql(str_sql);
                                    else
                                        ds_temp = main.dbservice.oracle_exec_selectsql(str_sql);

                                    if (ds_temp.Tables[0].Rows.Count > 0) //说明有记录，默认第一条  
                                    {
                                        d_convert = 0; d_cubage = 0; d_gross_weight = 0; d_net_weight = 0;
                                        d_convert = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["convert_modulus"].ToString().Trim());
                                        str_main_unit = "";
                                        str_sub_unit = "";
                                        str_main_unit = ds_temp.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                                        str_sub_unit = ds_temp.Tables[0].Rows[0]["sub_unit"].ToString().Trim();
                                        if (str_main_unit.Trim() == str_order_unit)//单位是主数量
                                        {
                                            dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else if (str_sub_unit.Trim() == str_order_unit)//辅数量
                                        {
                                            dgrow["plan_so_qty_s"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_m"] = Math.Round(Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()) / d_convert, 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }
                                        else
                                        {
                                            dgrow["plan_so_qty_m"] = (string)dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                            dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                            dgrow["order_unit"] = str_main_unit;
                                        }

                                        if (ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim() != "")
                                        {
                                            d_cubage = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["cubage"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_cubage = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim() != "")
                                        {
                                            d_gross_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["gross_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_gross_weight = 0;
                                        }
                                        if (ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim() != "")
                                        {
                                            d_net_weight = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["net_weight"].ToString().Trim());
                                        }
                                        else
                                        {
                                            d_net_weight = 0;
                                        }
                                        dgrow["convert_modulus"] = d_convert.ToString();
                                        //dgrow["plan_so_qty_s"] = Math.Round(d_convert * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["main_sub_flag"] = ds_temp.Tables[0].Rows[0]["main_sub_flag"].ToString().Trim();
                                        //dgrow["order_unit"] = ds_temp.Tables[0].Rows[0]["main_unit"].ToString().Trim();
                                        dgrow["plan_cubage"] = Math.Round(d_cubage * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["plan_gross_weight"] = Math.Round(d_gross_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                        dgrow["plan_net_weight"] = Math.Round(d_net_weight * Convert.ToDecimal(dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);
                                    }
                                    else
                                    {
                                        //DataRow dr = ((DataTable)dgv_execl.DataSource).NewRow();
                                        //dr["customer_order_no"] = (string)dgv_asn.Rows[n].Cells["original_order_no"].Value.ToString().Trim();
                                        //dr["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                        //((DataTable)dgv_execl.DataSource).Rows.Add(dr);
                                        //b_temp = true;
                                    }
                                }
                                catch (System.Exception ee)
                                {
                                    MessageBox.Show("查找商品档案失败!" + ee.ToString());
                                    return;
                                }
                                ds_update.Tables[0].Rows.Add(dgrow);
                            }
                        }
                        //如果有找不到档案的就存到临时表 
                        // if (b_temp) continue;
                        try
                        {
                            if (main.dbtype == "SQL")
                                main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                            else
                                main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);


                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }
                if (dgv_execl.Rows.Count > 0)
                {
                    main.g_class.DataGridViewToExcel2(dgv_execl);
                    DataTable dt_execl = new DataTable();
                    dt_execl.Columns.Add("customer_order_no");
                    dt_execl.Columns.Add("sku");
                    dgv_execl.DataSource = dt_execl;
                }
                progressBar1.Visible = false;
                progressBar1.Value = 0;

                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                MessageBox.Show(main.g_class.comm_getchangestring("导入成功,EXECL中有" + d_sum.ToString() + "行，导入成功" + d_count.ToString() + "行，失败" + Convert.ToString(d_sum - d_count) + "行。", main.g_info_dataset) + "!");
                #endregion
            }
            else if (comboBox1.Text.Trim() == "无锡江森原料库模板")
            {
                #region 保存 无锡江森原料库模板
                string str_sql;
                DataSet ds_temp;
                decimal d_convert = 0;
                // string str_main_unit = "", str_sub_unit = "";
                //DataSet ds_customer;
                progressBar1.Visible = true;
                string str_telephone = "";
                progressBar1.Maximum = dgv_asn.Rows.Count;
                progressBar1.Value = 0;
                for (int i = 0; i < dgv_asn.Rows.Count; i++)
                {
                    progressBar1.Value = i;
                    string str_sotype = dgv_asn.Rows[i].Cells["so_type"].Value.ToString().Trim();
                    string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();
                    string str_so_no = dgv_asn.Rows[i].Cells["so_no"].Value.ToString().Trim();
                    string str_so_day = dgv_asn.Rows[i].Cells["so_day"].Value.ToString().Trim();
                    string str_customer_sale_no = dgv_asn.Rows[i].Cells["customer_sale_no"].Value.ToString().Trim();
                    string str_order_unit = dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();
                    string str_customer_code = dgv_asn.Rows[i].Cells["customer_code"].Value.ToString().Trim();
                    string str_original_order_no = dgv_asn.Rows[i].Cells["original_order_no"].Value.ToString().Trim();
                    string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();


                    if (dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim() == "")
                        d_plan_so_qty_m = 0;
                    else
                        d_plan_so_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);

                    if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                        d_order_price = 0;
                    else
                        d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);



                    string str_standby_11 = dgv_asn.Rows[i].Cells["standby_11"].Value.ToString().Trim();
                    string str_standby_12 = dgv_asn.Rows[i].Cells["standby_12"].Value.ToString().Trim();

                    string str_project_name = dgv_asn.Rows[i].Cells["project_name"].Value.ToString().Trim();
                    string str_customer_name = dgv_asn.Rows[i].Cells["customer_name"].Value.ToString().Trim();
                    string str_receiver = dgv_asn.Rows[i].Cells["receiver"].Value.ToString().Trim();
                    string str_CARRIER_PHONE = dgv_asn.Rows[i].Cells["CARRIER_PHONE"].Value.ToString().Trim();

                    string str_need_time = dgv_asn.Rows[i].Cells["need_time"].Value.ToString().Trim();
                    string str_address = dgv_asn.Rows[i].Cells["address"].Value.ToString().Trim();
                    string str_rush_flag = dgv_asn.Rows[i].Cells["rush_flag"].Value.ToString().Trim();
                    string str_carrier_address = dgv_asn.Rows[i].Cells["carrier_address"].Value.ToString().Trim();

                    string str_standby_13 = dgv_asn.Rows[i].Cells["standby_13"].Value.ToString().Trim();
                    string str_standby_14 = dgv_asn.Rows[i].Cells["standby_14"].Value.ToString().Trim();
                    string str_memo2 = dgv_asn.Rows[i].Cells["memo2"].Value.ToString().Trim();
                    string str_MEMO = dgv_asn.Rows[i].Cells["MEMO"].Value.ToString().Trim();
                    string str_mechine_no = dgv_asn.Rows[i].Cells["mechine_no"].Value.ToString().Trim();
                    string str_work_position = dgv_asn.Rows[i].Cells["work_position"].Value.ToString().Trim();
                    string str_line_type = dgv_asn.Rows[i].Cells["line_type"].Value.ToString().Trim();
                    string str_sequence_no = dgv_asn.Rows[i].Cells["sequence_no"].Value.ToString().Trim();
                    string str_mechine_type = dgv_asn.Rows[i].Cells["mechine_type"].Value.ToString().Trim();
                    string str_eas = dgv_asn.Rows[i].Cells["eas_no"].Value.ToString().Trim();

                    //货主是否为空
                    if (str_consignor == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                        break;
                    }
                    //判断货主是否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_customer a where a.inv_org = '" + main.g_org + "' and a.consignor ='" + str_consignor + "' and   a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where  mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }
                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Consignor is not exists or haven't privilege", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是否为空
                    if (str_sku == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //出库单号是否为空
                    if (str_customer_sale_no == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a customer_sale_no ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //订货主数量是否为空
                    if (d_plan_so_qty_m == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input plan_so_qty_m ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //订单日期
                    if (str_so_day == "")
                    {
                        str_so_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                    }
                    //判断表头是否存在
                    int count;
                    string str_temp1 = "select count(*) from " + main.g_space + ".so_ship_header where inv_org = '" + main.g_org + "' and consignor='" + str_consignor + "'and so_no='" + str_so_no + "' ";
                    if (main.dbtype == "SQL")
                    {
                        count = main.dbservice.Sql_exec_selectint(str_temp1);
                    }
                    else
                    {
                        count = main.dbservice.oracle_exec_selectint(str_temp1);
                    }

                    if (count > 0)
                    {
                        //MessageBox.Show(main.g_class.comm_getchangestring("asn no have exists ", main.g_info_dataset) + "!" + str_consignor + "/" + str_asn_no);
                        //dgv_asn.Rows.Remove(dgv_asn.Rows[dgv_asn.Rows[i].Index]);
                        continue;
                    }
                    else
                    {
                        //str_so_no = main.g_class.comm_getaccountno("so_no");
                        string str_insert;
                        if (main.dbtype == "SQL")
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                        " so_flag,so_status,main_dist,made_time,maker,rush_flag,cross_flag,so_prior,wave_flag,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12" +
                                                                        ",project_name,CARRIER_PHONE,need_time,carrier_address,standby_13,standby_14,memo2,memo,eas_no,mechine_no,work_position,line_type,sequence_no,mechine_type)  " +
                                                            " values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                    "'" + str_customer_code + "','" + str_original_order_no + "','" + str_sotype + "','0','0','A', getdate(),'" + main.g_user + "','" + str_rush_flag + "','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_receiver + "','" + str_customer_name + "','" + str_standby_11 + "','" + str_standby_12 + "'" +
                                                                    ",'" + str_project_name + "','" + str_CARRIER_PHONE + "',convert(datetime,'" + str_need_time + "'),'" + str_carrier_address + "' ,'" + str_standby_13 + "','" + str_standby_14 + "','" + str_memo2 + "','" + str_MEMO + "'" +
                                                                    "'','" + str_eas + "','" + str_mechine_no + "','" + str_work_position + "','" + str_line_type + "','" + str_sequence_no + "','" + str_mechine_type + "')";
                        }
                        else
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                         " so_flag,so_status,main_dist,made_time,maker,,rush_flag,cross_flag,so_prior,wave_flag ,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12" +
                                                                         ",project_name,CARRIER_PHONE,telephone,need_time,address,carrier_address,standby_13,standby_14,memo2,memo)  " +
                                                             "  values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                      "'" + str_customer_code + "','" + str_original_order_no + "','" + str_sotype + "','0','0','A', sysdate,'" + main.g_user + "','0','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_receiver + "','" + str_customer_name + "','" + str_standby_11 + "','" + str_standby_12 + "')";
                        }

                        int k = 0;
                        ds_update.Tables[0].Clear();
                        bool b_temp = false;
                        for (int n = 0; n < dgv_asn.Rows.Count; n++)
                        {
                            str_oldno = dgv_asn.Rows[n].Cells["so_no"].Value.ToString().Trim();
                            str_oldconsignor = dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();

                            if (str_oldno == str_so_no && str_oldconsignor == str_consignor)
                            {
                                DataRow dgrow;
                                k = k + 1;
                                dgrow = ds_update.Tables[0].NewRow();
                                dgrow["inv_org"] = main.g_org;
                                dgrow["consignor"] = (string)dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                                dgrow["so_no"] = str_so_no;
                                dgrow["so_line_no"] = k;
                                dgrow["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                dgrow["pack_code"] = (string)dgv_asn.Rows[n].Cells["pack_code"].Value.ToString().Trim();
                                dgrow["order_price"] = (string)dgv_asn.Rows[n].Cells["order_price"].Value.ToString().Trim();
                                dgrow["lot_attribute1"] = (string)dgv_asn.Rows[n].Cells["lot_attribute1"].Value.ToString().Trim();
                                dgrow["lot_attribute2"] = (string)dgv_asn.Rows[n].Cells["lot_attribute2"].Value.ToString().Trim();
                                dgrow["lot_attribute3"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                dgrow["lot_attribute4"] = (string)dgv_asn.Rows[n].Cells["lot_attribute4"].Value.ToString().Trim();
                                dgrow["lot_attribute5"] = (string)dgv_asn.Rows[n].Cells["lot_attribute5"].Value.ToString().Trim();
                                dgrow["lot_attribute6"] = (string)dgv_asn.Rows[n].Cells["lot_attribute6"].Value.ToString().Trim();
                                dgrow["lot_attribute7"] = (string)dgv_asn.Rows[n].Cells["lot_attribute7"].Value.ToString().Trim();
                                dgrow["lot_attribute8"] = (string)dgv_asn.Rows[n].Cells["lot_attribute8"].Value.ToString().Trim();
                                dgrow["lot_attribute9"] = (string)dgv_asn.Rows[n].Cells["lot_attribute9"].Value.ToString().Trim();
                                dgrow["lot_attribute10"] = (string)dgv_asn.Rows[n].Cells["lot_attribute10"].Value.ToString().Trim();
                                dgrow["lot_attribute11"] = (string)dgv_asn.Rows[n].Cells["lot_attribute11"].Value.ToString().Trim();
                                dgrow["lot_attribute12"] = (string)dgv_asn.Rows[n].Cells["lot_attribute12"].Value.ToString().Trim();
                                dgrow["lot_attribute13"] = (string)dgv_asn.Rows[n].Cells["lot_attribute13"].Value.ToString().Trim();
                                dgrow["lot_attribute14"] = (string)dgv_asn.Rows[n].Cells["lot_attribute14"].Value.ToString().Trim();
                                dgrow["lot_attribute15"] = (string)dgv_asn.Rows[n].Cells["lot_attribute15"].Value.ToString().Trim();
                                dgrow["main_dist"] = "A";
                                dgrow["made_time"] = (string)DateTime.Now.ToString("yyyy.MM.dd").Trim();
                                dgrow["maker"] = main.g_user;
                                dgrow["standby_6"] = 0;
                                dgrow["standby_7"] = 0;
                                dgrow["standby_2"] = dgv_asn.Rows[n].Cells["standby_2"].Value.ToString().Trim();
                                dgrow["standby_3"] = dgv_asn.Rows[n].Cells["standby_3"].Value.ToString().Trim();
                                dgrow["so_status"] = "0";
                                dgrow["ship_qty_m"] = 0;
                                dgrow["ship_qty_s"] = 0;

                                dgrow["plan_so_qty_m"] = dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                dgrow["plan_so_qty_s"] = dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                if (dgv_asn.Rows[n].Cells["plan_cubage"].Value.ToString().Trim() == "")
                                {
                                    dgrow["plan_cubage"] = 0;
                                }
                                else
                                {
                                    dgrow["plan_cubage"] = dgv_asn.Rows[n].Cells["plan_cubage"].Value.ToString().Trim();
                                }
                                if (dgv_asn.Rows[n].Cells["plan_cubage"].Value.ToString().Trim() == "")
                                {
                                    dgrow["plan_gross_weight"] = 0;
                                }
                                else
                                {
                                    dgrow["plan_gross_weight"] = dgv_asn.Rows[n].Cells["plan_gross_weight"].Value.ToString().Trim();
                                }
                                if (dgv_asn.Rows[n].Cells["plan_net_weight"].Value.ToString().Trim() == "")
                                {
                                    dgrow["plan_net_weight"] = 0;
                                }
                                else
                                {
                                    dgrow["plan_net_weight"] = dgv_asn.Rows[n].Cells["plan_net_weight"].Value.ToString().Trim();
                                }

                                str_sql = "  SELECT *from WMS.mst_sku where inv_org='" + main.g_org + "' and consignor='" + dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim() + "' and sku='" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim() + "' and  main_dist <> 'D'";
                                try
                                {
                                    if (main.dbtype == "SQL")
                                        ds_temp = main.dbservice.Sql_exec_selectsql(str_sql);
                                    else
                                        ds_temp = main.dbservice.oracle_exec_selectsql(str_sql);

                                    if (ds_temp.Tables[0].Rows.Count > 0) //说明有记录，默认第一条  
                                    {

                                        d_convert = 0;
                                        d_convert = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["convert_modulus"].ToString().Trim());
                                        dgrow["convert_modulus"] = d_convert.ToString();
                                        dgrow["main_sub_flag"] = ds_temp.Tables[0].Rows[0]["main_sub_flag"].ToString().Trim();
                                    }

                                }
                                catch (System.Exception ee)
                                {
                                    MessageBox.Show("查找商品档案失败!" + ee.ToString());
                                    return;
                                }
                                ds_update.Tables[0].Rows.Add(dgrow);
                            }
                        }
                        //如果有找不到档案的就存到临时表 
                        if (b_temp) continue;
                        try
                        {
                            if (main.dbtype == "SQL")
                                main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                            else
                                main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);


                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }
                progressBar1.Visible = false;
                progressBar1.Value = 0;

                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                MessageBox.Show(main.g_class.comm_getchangestring("导入成功,EXECL中有" + d_sum.ToString() + "行，导入成功" + d_count.ToString() + "行，失败" + Convert.ToString(d_sum - d_count) + "行。", main.g_info_dataset) + "!");
                #endregion
            }
            else if (comboBox1.Text.Trim() == "无锡江森成品库模板")
            {
                #region 保存 无锡江森成品库模板
                string str_sql;
                DataSet ds_temp;
                decimal d_convert = 0;
                // string str_main_unit = "", str_sub_unit = "";
                //DataSet ds_customer;
                progressBar1.Visible = true;
                string str_telephone = "";
                progressBar1.Maximum = dgv_asn.Rows.Count;
                progressBar1.Value = 0;
                for (int i = 0; i < dgv_asn.Rows.Count; i++)
                {
                    progressBar1.Value = i;

                    string str_consignor = dgv_asn.Rows[i].Cells["consignor"].Value.ToString().Trim();
                    string str_so_no = dgv_asn.Rows[i].Cells["so_no"].Value.ToString().Trim();
                    string str_so_day = dgv_asn.Rows[i].Cells["so_day"].Value.ToString().Trim();
                    string str_customer_sale_no = dgv_asn.Rows[i].Cells["customer_sale_no"].Value.ToString().Trim();
                    string str_order_unit = dgv_asn.Rows[i].Cells["order_unit"].Value.ToString().Trim();
                    string str_customer_code = dgv_asn.Rows[i].Cells["customer_code"].Value.ToString().Trim();
                    string str_original_order_no = dgv_asn.Rows[i].Cells["original_order_no"].Value.ToString().Trim();
                    string str_sku = dgv_asn.Rows[i].Cells["sku"].Value.ToString().Trim();


                    if (dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim() == "")
                        d_plan_so_qty_m = 0;
                    else
                        d_plan_so_qty_m = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["plan_so_qty_m"].Value.ToString().Trim()), 4);

                    if (dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim() == "")
                        d_order_price = 0;
                    else
                        d_order_price = System.Math.Round(Convert.ToDecimal(dgv_asn.Rows[i].Cells["order_price"].Value.ToString().Trim()), 3);



                    string str_standby_11 = dgv_asn.Rows[i].Cells["standby_11"].Value.ToString().Trim();
                    string str_standby_12 = dgv_asn.Rows[i].Cells["standby_12"].Value.ToString().Trim();

                    string str_project_name = dgv_asn.Rows[i].Cells["project_name"].Value.ToString().Trim();
                    string str_customer_name = dgv_asn.Rows[i].Cells["customer_name"].Value.ToString().Trim();
                    string str_receiver = dgv_asn.Rows[i].Cells["receiver"].Value.ToString().Trim();
                    string str_CARRIER_PHONE = dgv_asn.Rows[i].Cells["CARRIER_PHONE"].Value.ToString().Trim();

                    string str_need_time = dgv_asn.Rows[i].Cells["need_time"].Value.ToString().Trim();
                    string str_address = dgv_asn.Rows[i].Cells["address"].Value.ToString().Trim();
                    string str_rush_flag = dgv_asn.Rows[i].Cells["rush_flag"].Value.ToString().Trim();
                    string str_carrier_address = dgv_asn.Rows[i].Cells["carrier_address"].Value.ToString().Trim();

                    string str_standby_13 = dgv_asn.Rows[i].Cells["standby_13"].Value.ToString().Trim();
                    string str_standby_14 = dgv_asn.Rows[i].Cells["standby_14"].Value.ToString().Trim();
                    string str_memo2 = dgv_asn.Rows[i].Cells["memo2"].Value.ToString().Trim();
                    string str_MEMO = dgv_asn.Rows[i].Cells["MEMO"].Value.ToString().Trim();

                    //货主是否为空
                    if (str_consignor == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a consignor ", main.g_info_dataset) + "!");
                        break;
                    }
                    //判断货主是否存在
                    str_where = " select count(*) from " + main.g_space + ".mst_customer a where a.inv_org = '" + main.g_org + "' and a.consignor ='" + str_consignor + "' and   a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where  mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
                    if (main.dbtype == "SQL")
                    {
                        li_count = main.dbservice.Sql_exec_selectint(str_where);
                    }
                    else
                    {
                        li_count = main.dbservice.oracle_exec_selectint(str_where);
                    }
                    if (li_count == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Consignor is not exists or haven't privilege", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //商品是否为空
                    if (str_sku == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a sku ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //出库单号是否为空
                    if (str_customer_sale_no == "")
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input a customer_sale_no ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //订货主数量是否为空
                    if (d_plan_so_qty_m == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Please input plan_so_qty_m ", main.g_info_dataset) + "!");
                        dgv_asn.Rows[i].Selected = true;
                        break;
                    }
                    //订单日期
                    if (str_so_day == "")
                    {
                        str_so_day = DateTime.Now.ToString("yyyy.MM.dd").Trim();
                    }
                    //判断表头是否存在
                    int count;
                    string str_temp1 = "select count(*) from " + main.g_space + ".so_ship_header where inv_org = '" + main.g_org + "' and consignor='" + str_consignor + "'and so_no='" + str_so_no + "' ";
                    if (main.dbtype == "SQL")
                    {
                        count = main.dbservice.Sql_exec_selectint(str_temp1);
                    }
                    else
                    {
                        count = main.dbservice.oracle_exec_selectint(str_temp1);
                    }

                    if (count > 0)
                    {
                        //MessageBox.Show(main.g_class.comm_getchangestring("asn no have exists ", main.g_info_dataset) + "!" + str_consignor + "/" + str_asn_no);
                        //dgv_asn.Rows.Remove(dgv_asn.Rows[dgv_asn.Rows[i].Index]);
                        continue;
                    }
                    else
                    {
                        //str_so_no = main.g_class.comm_getaccountno("so_no");
                        string str_insert;
                        if (main.dbtype == "SQL")
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                        " so_flag,so_status,main_dist,made_time,maker,rush_flag,cross_flag,so_prior,wave_flag,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12" +
                                                                        ",project_name,CARRIER_PHONE,need_time,carrier_address,standby_13,standby_14,memo2,memo)  " +
                                                            " values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                    "'" + str_customer_code + "','" + str_original_order_no + "','0','0','0','A', getdate(),'" + main.g_user + "','" + str_rush_flag + "','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_receiver + "','" + str_customer_name + "','" + str_standby_11 + "','" + str_standby_12 + "'" +
                                                                    ",'" + str_project_name + "','" + str_CARRIER_PHONE + "',convert(datetime,'" + str_need_time + "'),'" + str_carrier_address + "' ,'" + str_standby_13 + "','" + str_standby_14 + "','" + str_memo2 + "','" + str_MEMO + "')";
                        }
                        else
                        {
                            str_insert = "insert into " + main.g_space + ".so_ship_header (inv_org,consignor,so_no,so_day,customer_sale_no,customer_code,original_order_no,so_type," +
                                                                         " so_flag,so_status,main_dist,made_time,maker,,rush_flag,cross_flag,so_prior,wave_flag ,so_assign,standby_4,standby_5,address,telephone,receiver,customer_name,standby_11,standby_12" +
                                                                         ",project_name,CARRIER_PHONE,telephone,need_time,address,carrier_address,standby_13,standby_14,memo2,memo)  " +
                                                             "  values('" + main.g_org + "','" + str_consignor + "','" + str_so_no + "','" + str_so_day + "','" + str_customer_sale_no + "'," +
                                                                      "'" + str_customer_code + "','" + str_original_order_no + "','0','0','0','A', sysdate,'" + main.g_user + "','0','0','0','0','0',1,0,'" + str_address + "','" + str_telephone + "','" + str_receiver + "','" + str_customer_name + "','" + str_standby_11 + "','" + str_standby_12 + "')";
                        }

                        int k = 0;
                        ds_update.Tables[0].Clear();
                        bool b_temp = false;
                        for (int n = 0; n < dgv_asn.Rows.Count; n++)
                        {
                            str_oldno = dgv_asn.Rows[n].Cells["so_no"].Value.ToString().Trim();
                            str_oldconsignor = dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();

                            if (str_oldno == str_so_no && str_oldconsignor == str_consignor)
                            {
                                DataRow dgrow;
                                k = k + 1;
                                dgrow = ds_update.Tables[0].NewRow();
                                dgrow["inv_org"] = main.g_org;
                                dgrow["consignor"] = (string)dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim();
                                dgrow["so_no"] = str_so_no;
                                dgrow["so_line_no"] = k;
                                dgrow["sku"] = (string)dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim();
                                dgrow["pack_code"] = (string)dgv_asn.Rows[n].Cells["pack_code"].Value.ToString().Trim();
                                dgrow["order_price"] = (string)dgv_asn.Rows[n].Cells["order_price"].Value.ToString().Trim();
                                dgrow["lot_attribute1"] = (string)dgv_asn.Rows[n].Cells["lot_attribute1"].Value.ToString().Trim();
                                dgrow["lot_attribute2"] = (string)dgv_asn.Rows[n].Cells["lot_attribute2"].Value.ToString().Trim();
                                dgrow["lot_attribute3"] = (string)dgv_asn.Rows[n].Cells["lot_attribute3"].Value.ToString().Trim();
                                dgrow["lot_attribute4"] = (string)dgv_asn.Rows[n].Cells["lot_attribute4"].Value.ToString().Trim();
                                dgrow["lot_attribute5"] = (string)dgv_asn.Rows[n].Cells["lot_attribute5"].Value.ToString().Trim();
                                dgrow["lot_attribute6"] = (string)dgv_asn.Rows[n].Cells["lot_attribute6"].Value.ToString().Trim();
                                dgrow["lot_attribute7"] = (string)dgv_asn.Rows[n].Cells["lot_attribute7"].Value.ToString().Trim();
                                dgrow["lot_attribute8"] = (string)dgv_asn.Rows[n].Cells["lot_attribute8"].Value.ToString().Trim();
                                dgrow["lot_attribute9"] = (string)dgv_asn.Rows[n].Cells["lot_attribute9"].Value.ToString().Trim();
                                dgrow["lot_attribute10"] = (string)dgv_asn.Rows[n].Cells["lot_attribute10"].Value.ToString().Trim();
                                dgrow["lot_attribute11"] = (string)dgv_asn.Rows[n].Cells["lot_attribute11"].Value.ToString().Trim();
                                dgrow["lot_attribute12"] = (string)dgv_asn.Rows[n].Cells["lot_attribute12"].Value.ToString().Trim();
                                dgrow["lot_attribute13"] = (string)dgv_asn.Rows[n].Cells["lot_attribute13"].Value.ToString().Trim();
                                dgrow["lot_attribute14"] = (string)dgv_asn.Rows[n].Cells["lot_attribute14"].Value.ToString().Trim();
                                dgrow["lot_attribute15"] = (string)dgv_asn.Rows[n].Cells["lot_attribute15"].Value.ToString().Trim();
                                dgrow["main_dist"] = "A";
                                dgrow["made_time"] = (string)DateTime.Now.ToString("yyyy.MM.dd").Trim();
                                dgrow["maker"] = main.g_user;
                                dgrow["standby_6"] = 0;
                                dgrow["standby_7"] = 0;
                                dgrow["standby_2"] = dgv_asn.Rows[n].Cells["standby_2"].Value.ToString().Trim();
                                dgrow["standby_3"] = dgv_asn.Rows[n].Cells["standby_3"].Value.ToString().Trim();
                                dgrow["so_status"] = "0";
                                dgrow["ship_qty_m"] = 0;
                                dgrow["ship_qty_s"] = 0;

                                dgrow["plan_so_qty_m"] = dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                dgrow["plan_so_qty_s"] = dgv_asn.Rows[n].Cells["plan_so_qty_m"].Value.ToString().Trim();
                                if (dgv_asn.Rows[n].Cells["plan_cubage"].Value.ToString().Trim() == "")
                                {
                                    dgrow["plan_cubage"] = 0;
                                }
                                else
                                {
                                    dgrow["plan_cubage"] = dgv_asn.Rows[n].Cells["plan_cubage"].Value.ToString().Trim();
                                }
                                if (dgv_asn.Rows[n].Cells["plan_cubage"].Value.ToString().Trim() == "")
                                {
                                    dgrow["plan_gross_weight"] = 0;
                                }
                                else
                                {
                                    dgrow["plan_gross_weight"] = dgv_asn.Rows[n].Cells["plan_gross_weight"].Value.ToString().Trim();
                                }
                                if (dgv_asn.Rows[n].Cells["plan_net_weight"].Value.ToString().Trim() == "")
                                {
                                    dgrow["plan_net_weight"] = 0;
                                }
                                else
                                {
                                    dgrow["plan_net_weight"] = dgv_asn.Rows[n].Cells["plan_net_weight"].Value.ToString().Trim();
                                }

                                str_sql = "  SELECT *from WMS.mst_sku where inv_org='" + main.g_org + "' and consignor='" + dgv_asn.Rows[n].Cells["consignor"].Value.ToString().Trim() + "' and sku='" + dgv_asn.Rows[n].Cells["sku"].Value.ToString().Trim() + "' and  main_dist <> 'D'";
                                try
                                {
                                    if (main.dbtype == "SQL")
                                        ds_temp = main.dbservice.Sql_exec_selectsql(str_sql);
                                    else
                                        ds_temp = main.dbservice.oracle_exec_selectsql(str_sql);

                                    if (ds_temp.Tables[0].Rows.Count > 0) //说明有记录，默认第一条  
                                    {

                                        d_convert = 0;
                                        d_convert = Convert.ToDecimal(ds_temp.Tables[0].Rows[0]["convert_modulus"].ToString().Trim());
                                        dgrow["convert_modulus"] = d_convert.ToString();
                                        dgrow["main_sub_flag"] = ds_temp.Tables[0].Rows[0]["main_sub_flag"].ToString().Trim();
                                    }

                                }
                                catch (System.Exception ee)
                                {
                                    MessageBox.Show("查找商品档案失败!" + ee.ToString());
                                    return;
                                }
                                ds_update.Tables[0].Rows.Add(dgrow);
                            }
                        }
                        //如果有找不到档案的就存到临时表 
                        if (b_temp) continue;
                        try
                        {
                            if (main.dbtype == "SQL")
                                main.dbservice.Sql_insert_dataset(str_insert, ds_update, str_updatesql);
                            else
                                main.dbservice.oracle_insert_dataset(str_insert, ds_update, str_updatesql);


                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save ", main.g_info_dataset) + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }
                progressBar1.Visible = false;
                progressBar1.Value = 0;

                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                MessageBox.Show(main.g_class.comm_getchangestring("导入成功,EXECL中有" + d_sum.ToString() + "行，导入成功" + d_count.ToString() + "行，失败" + Convert.ToString(d_sum - d_count) + "行。", main.g_info_dataset) + "!");
                #endregion
            }
        }
        //取消
        private void btn_cancel_Click(object sender, EventArgs e)
        {
            if (dgv_asn.Rows.Count > 0)
            {
                dgv_asn.DataSource = null;
                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = true;
                btn_inexcel.Enabled = true;
            }
        }
        //导出
        private void btn_outexcel_Click(object sender, EventArgs e)
        {
            //int i_extbatchno;
            if (dgv_export.Rows.Count > 0)
            {
                //string str_llsql;
                //DataSet ds_llsql =new DataSet();
                ////取导出批次号
                //str_llsql ="select page_no from "+  main.g_space +".mst_account where bill_id ='extbatchno'";
                //if(main.dbtype =="SQL")
                //    ds_llsql =main.dbservice.Sql_exec_selectsql(str_llsql);
                //else
                //    ds_llsql =main.dbservice.oracle_exec_selectsql(str_llsql);
                //i_extbatchno =System.Convert.ToInt32(ds_llsql.Tables[0].Rows[0][0].ToString().Trim()) + 1;
                ////更新导出批次号 
                //string str_sql;
                //DataSet ds_sql =new DataSet();



                main.g_class.DataGridViewToExcel(dgv_export);
                string str_update;
                if (main.dbtype == "SQL")
                    str_update = "update " + main.g_space + ".so_ship_header set ext_dist ='1',updater ='" + main.g_user + "',update_time =getdate()  where inv_org = '" + main.g_org + "' and isnull(ext_dist,'0') ='0' and (so_flag = '1'or so_status in('4','5'))  ";
                else
                    str_update = "update " + main.g_space + ".so_ship_header set ext_dist ='1',updater = '" + main.g_user + "',update_time = sysdate  where inv_org = '" + main.g_org + "' and nvl(ext_dist,'0') ='0' and (so_flag = '1'or so_status in('4','5'))  ";
                try
                {
                    if (main.dbtype == "SQL")
                    {
                        main.dbservice.Sql_exec_commandsql(str_update);
                    }
                    else
                    {
                        main.dbservice.oracle_exec_commandsql(str_update);
                    }
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to Export", main.g_info_dataset) + "!" + ee.ToString());
                    Cursor.Current = Cursors.Default;
                    return;
                }
                btn_save.Enabled = false;
                btn_cancel.Enabled = false;
                btn_query.Enabled = true;
                btn_outexcel.Enabled = false;
                btn_inexcel.Enabled = true;
                MessageBox.Show(main.g_class.comm_getchangestring("Success to Export", main.g_info_dataset) + "!");
            }
        }
        //删除
        private void btn_del_Click(object sender, EventArgs e)
        {
            if (dgv_asn.Rows.Count > 0)
            {
                dgv_asn.Rows.Remove(dgv_asn.Rows[dgv_asn.CurrentRow.Index]);
            }
        }

        private void btn_query_Click(object sender, EventArgs e)
        {
            DataSet ds_tmp = new DataSet();
            string str_temp;
            dgv_export.Visible = true;
            dgv_asn.Visible = false;
            dgv_asn.DataSource = null;
            if (main.dbtype == "SQL")

                str_temp = "select a.consignor,a.so_no,b.sku,b.pack_code,sum(isnull(b.plan_so_qty_m,0)) as plan_so_qty_m,sum(isnull(b.ship_qty_m,0)) as ship_qty_m,a.so_day " +
                             " from " + main.g_space + ".so_ship_header a," + main.g_space + ".so_ship_detail b  where a.inv_org = '" + main.g_org + "' and a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no and " +
                            "isnull(a.ext_dist,'0') = '0' and (a.so_status = '1'or a.so_status in ('4','5')) ";
            else
                str_temp = "select a.consignor,a.so_no,b.sku,b.pack_code,sum(nvl(b.plan_so_qty_m,0)) as plan_so_qty_m,sum(nvl(b.ship_qty_m,0)) as ship_qty_m,a.so_day " +
                           " from " + main.g_space + ".so_ship_header a," + main.g_space + ".so_ship_detail b  where a.inv_org = '" + main.g_org + "' and a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no and " +
                           "nvl(a.ext_dist,'0') = '0' and (a.so_status = '1'or a.so_status in ('4','5')) ";

            //判断是否有货主
            if (cb_consignor.Text.Trim() != "")
            {
                str_temp = str_temp + " and a.consignor = '" + cb_consignor.Text.Trim() + "'  ";
            }
            else //没有货主提取有权限的所有货主
            {
                str_temp = str_temp + " and a.consignor in (select a.consignor from " + main.g_space + ".mst_customer a," + main.g_space + ".sys_user b," + main.g_space + ".sys_user_customer c" +
                           " where b.inv_org = c.inv_org and b.user_id = c.user_id and c.inv_org = a.inv_org and c.consignor = a.consignor and b.inv_org = '" + main.g_org + "' and b.user_id = '" + main.g_user + "' and a.consignor_flag='1')  ";
            }
            if (tb_so_no.Text.Trim() != "")
            {
                str_temp += " and a.so_no='" + tb_so_no.Text.Trim() + "'";
            }
            str_temp += " and a.so_day between '" + dtp_made_time.Text.ToString().Trim() + "' and '" + dtp_made_time_end.Text.ToString().Trim() + "'  group by a.consignor,a.so_no,b.sku,b.pack_code,a.so_day  order by a.so_no";
            try
            {
                if (main.dbtype == "SQL")
                    ds_tmp = main.dbservice.Sql_exec_selectsql(str_temp);
                else
                    ds_tmp = main.dbservice.oracle_exec_selectsql(str_temp);

            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Information of bill's detail", main.g_info_dataset) + "!" + ee.ToString());

                return;
            }
            if (ds_tmp.Tables[0].Rows.Count > 0)
                dgv_export.DataSource = ds_tmp.Tables[0];
            else
                dgv_export.DataSource = null;

            btn_save.Enabled = false;
            btn_cancel.Enabled = false;
            btn_query.Enabled = true;
            btn_outexcel.Enabled = true;
            btn_inexcel.Enabled = false;

            dgv_export.Visible = false;
            dgv_asn.Visible = true;
            dgv_export.DataSource = null;
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void dgv_asn_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void cb_consignor_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str_cust;
            str_cust = cb_consignor.Text.Trim();
            tb_cusname.Text = main.g_class.comm_findname(str_cust, dscustomer);
        }

        private void cb_consignor_TextChanged(object sender, EventArgs e)
        {
            string str_cust;
            str_cust = cb_consignor.Text.Trim();
            tb_cusname.Text = main.g_class.comm_findname(str_cust, dscustomer);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            btn_save.Enabled = true;
            btn_cancel.Enabled = true;
            btn_query.Enabled = false;
            btn_outexcel.Enabled = false;
            btn_inexcel.Enabled = true;
        }

        private void groupBox3_Enter(object sender, EventArgs e)
        {

        }

    }
}